Search code examples
visual-studiodelphiwebbrowser-controltwebbrowser

Why the script does not work / the button is not pressed in the web browser (control/component)?


I wrote two programs. One on Delphi 2009, another on Visual Studio 2019 to view the same html page. I used the twebbrowser component (or webbrowser control). In both cases, clicking the button on the page in window of webbrowser does not work and the corresponding java script does not execute. The page displays a message that my browser is out of date. Attempts to press a button programmatically failed (nothing happens, there is no error either). But the button work in the Internet Explorer 11. The code of the button:

<div id="showAll" class="showAllClass block" onclick="showAll(1, this)">
  <a href="javascript:void(0);">Show all</a>
</div>

The code for Delphi:

var
  A : IHTMLElement3;
  doc : IHTMLDocument3;
  v   : OleVariant;
begin
  A := (MyWebbrowser.Document as IHTMLDocument3).getElementById('showAll') as IHTMLElement3;
  v:=Unassigned;
  (A as IHTMLElement3).FireEvent('onclick',v);
end;

The code for C#:

webBrowser1.Document.GetElementById("showAll").InvokeMember("onclick");

Solution

  • I found answer here How can I get the WebBrowser control to show modern contents? as addition of

    "YourApplicationFileName.exe"=dword:00002af9
    "YourApplicationFileName.vshost.exe"=dword:00002af9
    

    to Registry by path

    HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION