如何使 VB.NET webbrowser 控件看起来像一个与网站不同的 Web 浏览器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18543173/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 14:53:09  来源:igfitidea点击:

How to make VB.NET webbrowser controls look like a different Web Browser to websites

vb.netinternet-explorerinternet-explorer-9

提问by Samy Bencherif

Some websites, especially the ones that are fancy with HTML 5 and whatnot, will verify the browser that you are using, and give you a little warning message like: "Warning you are using an untested browser" if your web browser isn't in their little white-list.

某些网站,尤其是那些喜欢 HTML 5 之类的网站,会验证您正在使用的浏览器,如果您的 Web 浏览器不在他们的小白名单。

enter image description here

在此处输入图片说明

Sadly these websites do not recognize IE controls as being Internet Explorer Browsers, so sometimes they show unnecessary warnings/errors

遗憾的是,这些网站无法将 IE 控件识别为 Internet Explorer 浏览器,因此有时它们会显示不必要的警告/错误

Is there any feasible way for me to make my webbrowser control show up as Internet Explorer 9 instead of whatever it actually shows up for, that way if the website has already tested Internet Explorer 9 for functionality, it will not show any errors.

有什么可行的方法可以让我的 webbrowser 控件显示为 Internet Explorer 9 而不是它实际显示的任何内容,这样如果网站已经测试了 Internet Explorer 9 的功能,它就不会显示任何错误。

Thank you!

谢谢!

回答by Yuriy Galanter

By default WebBrowser control is detected as IE7, to see this - try to navigate to "What is My User Agent":

默认情况下,WebBrowser 控件被检测为 IE7,要查看此内容 - 尝试导航到“我的用户代理是什么”:

WebBrowser1.Navigate("http://www.whatsmyuseragent.com/")

Easiest way to change this is to pass user agent of a different browser as the last parameter of "Navigate" method. Open http://www.whatsmyuseragent.com/in your normal IE9, copy the displayed string and use it as parameter e.g.:

改变这一点的最简单方法是将不同浏览器的用户代理作为“导航”方法的最后一个参数传递。在正常的 IE9 中打开http://www.whatsmyuseragent.com/,复制显示的字符串并将其用作参数,例如:

WebBrowser1.Navigate("http://www.whatsmyuseragent.com/", Nothing, Nothing, "User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)")

回答by EricLaw

The problem you're hitting is that, by-default, IE Web Browser controls run in legacy Compatibility modes. To resolve that, set Feature_Browser_Emulationfor your process (ensure you write to both the 32bit and 64bit registry keys if your project is compiled for AnyCPU. See webbrowser using ie10 c# winformfor more details.

您遇到的问题是,默认情况下,IE Web 浏览器控件在旧版兼容模式下运行。要解决这个问题,请Feature_Browser_Emulation为您的进程设置(如果您的项目是为AnyCPU编译的,请确保您写入 32 位和 64 位注册表项。有关更多详细信息,请参阅使用 ie10 c# winform 的 webbrowser

If you wanted to send a differentuser-agent string (which is such sites determine what browser version you're using) you need to use the URLMon API UrlMkSetSessionOptionas discussed here: http://blogs.msdn.com/b/ieinternals/archive/2009/10/08/extending-the-user-agent-string-problems-and-alternatives.aspx

如果您想发送不同的用户代理字符串(此类站点决定您使用的浏览器版本),您需要使用UrlMkSetSessionOption此处讨论的 URLMon API :http: //blogs.msdn.com/b/ieinternals/存档/2009/10/08/extending-the-user-agent-string-problems-and-alternatives.aspx