WebBrowser控件和JavaScript错误控件、错误、WebBrowser、JavaScript

2023-09-02 21:35:35 作者:人间风月是你

当我访问该页面的浏览器(IE9),浏览器渲染ok了。

When I access the page with the browser (ie9), the browser is rendering ok.

当我使用WebBrowser控件我有JavaScript错误。

When I use the WebBrowser control I have JavaScript errors.

我知道我能晚饭preSS脚本错误,但我希望他们能正确运行,因为它们影响了渲染和页面的功能。

I know I can suppress the scripts errors, but I want them to run correctly, because they affect the rendering and the functionality of the page.

我该如何解决这个问题呢?我可以直接在Windows窗体集成IE9,并使用类似的方法,如使用WebBrowser控件(浏览,获取ID,调用点击)?

How can I solve this problem ? Can I integrate IE9 directly in the Windows Form and use similar methods like with the WebBrowser control (navigate,get id, invoke click) ?

感谢。

推荐答案

我会做的是一个对象分配给webbrowser.ObjectForScripting,然后注入一个JavaScript函数,分配windown.onerror到一个包装调用的外部脚本主机应用程序。像:

What I would do is assign an object to webbrowser.ObjectForScripting and then inject a javascript function that assigns windown.onerror to a wrapper that calls the external script in the host app. Like:

window.onerror = function(message, url, lineNumber) 
{ 
  window.external.errorHandler(message, url, lineNumber);
}

Refere到: http://notions.okuda.ca/2009/06/11/calling-javascript-in-a-webbrowser-control-from-c/

Refere to: http://notions.okuda.ca/2009/06/11/calling-javascript-in-a-webbrowser-control-from-c/