Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Allowing javascript to run on a windows form web browser

Tags:

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

like image 856
Ryanas Avatar asked Aug 05 '14 15:08

Ryanas


People also ask

How use JavaScript in Windows form application?

Step 1- Initially create a new window based project. Execute Visual Studio then: "File" -> "New" -> "Project..." then select "Windows" -> "Windows Forms Application". Step 2- Then drag and drop a web browser control to the Windows Forms form and also drag and drop a Print Dialog Control onto the form.

Can we use JavaScript in Windows application?

No. JavaScript needs a runtime environment. Such a runtime environment is present in browser, but not in Windows Forms. In Windows Forms, you can use all the features of C# or any other programming language on the .

How do I run a Windows Form application in my browser?

You can right-click on the icon and then click on the 'Open Web Browser'. A Web browser window will open and your application will be running inside.


Video Answer


2 Answers

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_MACHINE\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION for 64-bit or 32-bit only machines.

Or go to HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_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.

like image 80
Ryanas Avatar answered Sep 28 '22 11:09

Ryanas


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

This will work out , This is the summery of Ryan Singh's answer

like image 20
PrathapG Avatar answered Sep 28 '22 10:09

PrathapG