简体   繁体   English

如何在WebBrowser控件中禁用JavaScript警告?

[英]How can I disable JavaScript warnings in the WebBrowser control?

I'm using the WebBrowser control and mshtml.dll. 我正在使用WebBrowser控件和mshtml.dll。 When I simulate click on link <a href='..'>..</a> , the WebBrowser shows a JavaScript warning dialog: 模拟时,单击链接<a href='..'>..</a> ,WebBrowser会显示一个JavaScript警告对话框:

Unable to move the focus to the element as it is in the invisible ,off or can't have a focus. 无法将焦点移至元素处于不可见,关闭或没有焦点的位置。

The code I use to simulate the click: 我用来模拟点击的代码:

anchor.click();

...where anchor has the type: HTMLAnchorElementClass ...其中的anchor类型为: HTMLAnchorElementClass

So I want to disable all JavaScript warnings in my component WebBrowser. 因此,我想禁用组件WebBrowser中的所有JavaScript警告。 How might I do this? 我该怎么办?

我不确定您是否引用Windows窗体WebBrowser控件,但它具有ScriptErrorsSuppressed属性以禁用脚本错误消息。

You have to find the place where you are doing anchor.click(); 您必须找到执行anchor.click();的位置anchor.click(); and either remove it or replace it with if(anchor.clientHeight != 0){anchor.click();} . 并删除它或将其替换为if(anchor.clientHeight != 0){anchor.click();}

It's possible to work around this particular warning by having the link element be part of the page and visible. 通过使link元素成为页面的一部分并可见,可以解决此特定警告。

Calling the click() method actually does more than execute an onclick handler and navigate the browser, it also focuses the element - just like when a real click happens. 实际上,调用click()方法不仅执行onclick处理程序并浏览浏览器,而且还使元素集中-就像发生真正单击时一样。 If the element is offscreen, this behavior is not possible. 如果该元素不在屏幕上,则此行为是不可能的。

Simply attach the link to the body to not have this warning show up. 只需将链接附加到主体即可不显示此警告。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM