IWebBrowser2似乎未执行javascript [英] IWebBrowser2 seemingly not executing javascript

查看:100
本文介绍了IWebBrowser2似乎未执行javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们程序的用户有时不得不从第三方网站上下载数据库,这需要他们登录并指定参数以获取正确的数据库.我试图将其合并到我们的程序中,以便用户不必打开单独的浏览器,也可以使我们的程序在下载后即可访问数据库.

Users of our program occasionally have to download databases from a third-party website that requires them to log-in and specify parameters to get the correct database. I am trying to incorporate this into our program so that users don’t have to open a separate browser and also so that our program can access the database upon being downloaded.

我已按照Microsoft使用MFC托管WebBrowser控件"中的说明,将网络浏览器嵌入对话框中,但显然似乎无法正确执行某些网站的javascript.我可以使用IE,Chrome或Firefox浏览网站.但是,通过嵌入式浏览器导航网站会产生多个脚本错误,其行为与独立浏览器完全不同,并且最终会阻止用户访问所需的数据库.我已经检查了网站的源代码,似乎未访问javascript中指定的某些默认值,并且未执行某些功能.我收到的一些错误消息是:

I’ve embedded a web browser into a dialog as specified in Microsoft’s "Using MFC to Host a WebBrowser Control", but it apparently doesn’t seem to properly execute certain website’s javascript. I have no trouble navigating the website using IE, Chrome or Firefox. However, navigating the website through the embedded browser generates multiple script errors, behaves in a completely different manner than in a stand-alone browser and ultimately, prevents the user from accessing the required database. I’ve examined the website source code and it appears that certain defaults specified within the javascript are not being accessed and certain functions are not being executed. Some of the error messages I receive are:

‘console’ is undefined ( the javascript is attempting to log messages to the console - I don’t think this has much effect on website content )

The value of the property ‘SelectSpectralModel’ is null or undefined, not a Function object 

(SelectSpectralModel是一个javascript函数,用于确定显示哪些信息框,用户从中选择所需的内容

( SelectSpectralModel is a javascript function that determines which information boxes appear, from which the user selects their desired content )

我注意到在Microsoft Visual Studio调试模式下运行代码时,尝试浏览网站时经常出现以下消息:

I’ve noticed that while running the code in Microsoft Visual Studio Debug mode, the following message appears frequently while trying to navigate the website:

First-chance exception ….: Microsoft C++ exception: Js::JavascriptExceptionObject at memory location…..

我在调试中启用了异常以试图查找错误,但是当代码中断时,我对错误的实际发生位置感到困惑.

I enabled Exceptions in debug in an attempt to locate the error, but when the code breaks, I’m at a loss as to where the error is actually occurring.

我似乎无法在线找到有关发生这种情况的任何信息.我找到了很多有关IWebBrowser2的信息,但没有与此特定问题有关的信息.我还找到了有关某人使用OLE Automation运行Internet Explorer实例的解决方法(针对另一个问题,但似乎可能有所帮助),但是在此时,我必须做更多的阅读来弄清楚如何做到这一点.

I can’t seem to locate any information online as to why this is happening. I’ve located a lotta information about IWebBrowser2, but nothing that pertains to this particular problem. I’ve also located something about a workaround someone came up with ( for a different problem, but it seems like it might help ) using OLE Automation to run an instance of Internet Explorer, but at this point in time, I’d have to do a lot more reading to work out how this is done.

我可以尝试解决此问题的任何帮助,甚至在合并变通方法方面的帮助也将不胜感激.

Any help I could get trying to remedy this problem or even some help in incorporating a workaround would be greatly appreciated.

推荐答案

Microsoft嵌入式Web浏览器控件以7的文档模式运行.因此,如果您要使用Fiddler来查看User-agent字符串,则会看到IE 7用户代理字符串.它也使用IE7的呈现和Web标准.

The Microsoft Embedded Web Browser control runs in a Document mode of 7. So if you were to use Fiddler to see the User-agent-string you would see the IE 7 User agent string. It uses the rendering and web standards of IE7 as well.

要覆盖此内容并使其使用IE11标准,您将必须创建一个特定于您的可执行文件的注册表项.

To override this and have it use IE11 standards you will have to create a registry entry specific to your executable.

 HKEY_LOCAL_MACHINE (or HKEY_CURRENT_USER)\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION

                 contoso.exe = (DWORD) 00009000

请参见 MSDN文档

See the MSDN documentation on this

这篇关于IWebBrowser2似乎未执行javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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