Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
128 views
in Technique[技术] by (71.8m points)

c# - Allowing javascript to run on a windows form web browser

I want to use a Web Browser to access a website that uses JavaScript on load. I understand that Web Browser is a wrapper of the current installed version of Internet Explorer. However, testing the website on Internet Explorer yields no errors but does not work if I use the Web Browser to access the content.

I have also looked at my internet security settings to ensure it is enabled.

The issue I get is;

Error in Web Browser

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Awkwardly enough, I found the answer moments after posting this but I thought anyone who comes across the same problem as me will find solace in this answer;

It seems downloading the latest version of Internet Explorer is not enough and you must explicitly specify the version of IE to use by adding a new registry key.

HTML fix;

<!DOCTYPE html> 
<html> 
  <head> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge" /> 
    ... other headers
  </head>
  <body>
    ... content
  </body>
</html>  

Via registry;

Go to HKEY_LOCAL_MACHINESOFTWAREMicrosoftInternet ExplorerMAINFeatureControlFEATURE_BROWSER_EMULATION for 64-bit or 32-bit only machines.

Or go to HKEY_LOCAL_MACHINESOFTWAREWow6432NodeMicrosoftInternet ExplorerMAINFeatureControlFEATURE_BROWSER_EMULATION for 32-bit on 64-bit systems (It cannot hurt to add keys to both locations if you have them. If you do not have them, you can make the folders yourself).

Create a new DWORD key and name it the name of your application e.g. "myapp.exe" and then edit the value of the key. There are many different values you can add depending on the IE version you want to emulate. I entered 11001 (as a decimal value - 0x2AF9 in HEX) which emulates IE 11 (many more values located at: http://msdn.microsoft.com/en-us/library/ee330730%28v=vs.85%29.aspx#browser_emulation).

If you're using Visual Studio like I am, you'll notice that this method might not even work. However, it does work. You need to manually open the .exe file using Explorer or terminal rather than run the project on Visual Studio.

If you wish to run the program on Visual Studio then consider adding a key for "myapp.vshost.exe" as this is used for debugging.

More information and source is from; http://weblog.west-wind.com/posts/2011/May/21/Web-Browser-Control-Specifying-the-IE-Version.

I hope this helps anyone with any issue regarding your Web Browser perhaps using the wrong IE version as a wrapper or functions are not working as intended.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...