WebBrowser控件和JavaScript错误 [英] WebBrowser control and JavaScript errors

查看:187
本文介绍了WebBrowser控件和JavaScript错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我访问该页面的浏览器(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到: <一href="http://notions.okuda.ca/2009/06/11/calling-javascript-in-a-webbrowser-control-from-c/">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/

这篇关于WebBrowser控件和JavaScript错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆