'JSON'未定义 [英] 'JSON' is undefined

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

问题描述

我正在尝试将 Chromecast后台网站加载到ac# WebBrowser ,但得到:

I'm trying to load the Chromecast background website into a c# WebBrowser but am getting:

我以为是因为Web浏览器默认情况下使用的是IE7(?),可能无法与网站中的JS很好地配合使用.我试图将注册FEATURE_BROWSER_EMULATION更新为9000,希望强制webbrowser使用IE9框架.但是我仍然遇到相同的错误.

I assumed it was happening because the webbrowser is using IE7 by default(?) which might not play well with the JS in the website. I tried to updated the registery FEATURE_BROWSER_EMULATION to 9000 hoping force the webbrowser to use IE9 framework. But I still get the same errors.

此任务的浏览器是否基本?是否有解决此问题的方法?

Is the webbrowser to basic for this task or is there a way around this problem?

因此,当我打印webbrowser.version时,我得到:版本:11.0.9600.16518.我拥有的是IE的当前版本.如果我打开IE11并导航到该URL,则效果很好.不确定webbroswer为何会出问题.

So when I print the webbrowser.version I get: Version: 11.0.9600.16518. Which is the current version of IE I have. If I open IE11 and navigate to the url its works great. Not sure why the webbroswer is having an issue.

我尝试使用以下代码将 JSON解析器注入网页:

I tried to inject a JSON Parser into the webpage with this code:

HtmlDocument doc = webBrowser1.Document;
            Console.WriteLine(doc);
            HtmlElement head = doc.GetElementsByTagName("head")[0];
            HtmlElement s = doc.CreateElement("script");
            s.SetAttribute("type", "text/javascript");
            s.SetAttribute("src", "http://192.168.1.23:10000/JSON-js-master/json2.js");
            head.AppendChild(s);

我尝试使用本地和外部ips引用主机文件.似乎没有什么不同.

I tried with local and external ips referencing the host file. Didn't seem the make a difference.

推荐答案

显然,当WebBrowser控件运行时,它以计算机上安装的IE版本运行,但以IE7兼容模式运行.尝试加载您列出的链接需要使用更现代的浏览器.实际上,您请求的页面需要IE10或更高版本.

Apparently when the WebBrowser control runs, it runs in in the version of IE installed on the computer, but it runs in IE7 compatibility mode. Trying to load the link you listed requires a more modern browser. As a matter of fact, the page you requested needs IE10 or higher.

您确实需要在注册表中更改浏览器仿真设置,以便WebBrowser控制用户使用更现代的IE功能集:

You do need to change the browser emulation settings in the registry so that the WebBrowser control users a more modern IE feature set:

Internet功能控件

正如您在问题中已经说过的,注册表中需要调整的两个区域是:

As you already said in your question, the two areas in the registry that need to be adjusted are:

HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Internet Explorer \ Main \ FeatureControl \ FEATURE_BROWSER_EMULATION

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION

HKEY_LOCAL_MACHINE \ SOFTWARE \ Wow6432Node \ Microsoft \ Internet Explorer \ Main \ FeatureControl \ FEATURE_BROWSER_EMULATION

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION

在这两个位置的每个位置,您的应用程序的进程名称都包含一个DWORD值集,该值指示了兼容性级别.在 Internet功能上可以找到特定的值控件帮助页面.该文件的名称是您的应用程序"MyApplication1.exe"的名称,或者,如果您是从Visual Studio中运行的,则为"MyApplication1.vshost.exe".

In each of those two locations, the process name of your applications is included with a DWORD value set indicating the level of compatibility. The specific values are found on the Internet Feature Controls help page. The names of the file is the name of you application "MyApplication1.exe", or if you're running from within Visual Studio, it is "MyApplication1.vshost.exe".

因为我已安装IE 11,所以将浏览器仿真设置设置为11001,并且它适用于您链接的网页.

Because I have IE 11 installed, I set the browser emulation setting to 11001 and it worked for your linked webpage.

这篇关于'JSON'未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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