为什么脚本不起作用/在 Web 浏览器中没有按下按钮(控件/组件)?



我写了两个程序。一个在Delphi 2009上,另一个在Visual Studio 2019上查看相同的html页面。我使用了twebbrowser组件(或webbrowser控件(。在这两种情况下,单击Web浏览器窗口中页面上的按钮都不起作用,并且相应的java脚本不会执行。该页面显示一条消息,指出我的浏览器已过期。尝试以编程方式按下按钮失败(没有任何反应,也没有错误(。但是该按钮在Internet Explorer 11中有效。按钮的代码:

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

德尔福的代码:

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;

C# 的代码:

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

我在这里找到了答案 如何使 Web 浏览器控件显示新式内容? 作为添加

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

到按路径注册

HKEY_CURRENT_USERSoftwareMicrosoftInternet ExplorerMainFeatureControlFEATURE_BROWSER_EMULATION

最新更新