开发者

How can I disable JavaScript warnings in the WebBrowser control?

开发者 https://www.devze.com 2022-12-08 03:26 出处:网络
I\'m using the WebBrowser control and mshtml.dll. When I simulate click on link <a href=\'..\'>..</a>, the WebBrowser shows a JavaScript warning dialog:

I'm using the WebBrowser control and mshtml.dll. When I simulate click on link <a href='..'>..</a>, the WebBrowser shows a JavaScript warning dialog:

Unable to move the focus to the 开发者_C百科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

So I want to disable all JavaScript warnings in my component WebBrowser. How might I do this?


I'm not sure if your referring to the windows forms WebBrowser control but it has the ScriptErrorsSuppressed property for disabling script error messages.


You have to find the place where you are doing anchor.click(); and either remove it or replace it with 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.

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. If the element is offscreen, this behavior is not possible.

Simply attach the link to the body to not have this warning show up.

0

精彩评论

暂无评论...
验证码 换一张
取 消