Javascript is disabled in MS Access WebBrowser Control when viewing a local file

I have seen similar messages before, but none of the solutions that I have seen on the Internet seem to work for me.

I am trying to use a WebBrowser control to display a locally stored HTML file that uses the JavaScript API for Google Maps, but JavaScript remains stubborn.

To check the problem, I made a simple page using Google Maps based on https://developers.google.com/maps/documentation/javascript/examples/map-simple . I also added a button to check if JavaScript is working

c: \ map-test.html works fine in both Firefox and IE.

<!DOCTYPE html> <html> <head> <title>Google Maps JavaScript API v3 Example: Map Simple</title> <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"> <meta charset="utf-8"> <style> html, body, #map_canvas { margin: 0; padding: 0; height: 100%; } </style> <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script> <script> var map; function initialize() { var mapOptions = { zoom: 8, center: new google.maps.LatLng(-34.397, 150.644), mapTypeId: google.maps.MapTypeId.ROADMAP }; map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions); } google.maps.event.addDomListener(window, 'load', initialize); </script> </head> <body> <input type="button" onclick="alert('JavaScript Functioning');" value="Test JavaScript"> <div id="map_canvas"></div> </body> </html> 

Then I created the MS Access form using a WebBrowser control named cWebBrowser and added the c: \ map-test.html download method. The Google Maps interface does not load, and the test button does not work.

 Private Sub Form_Current() Me.cWebBrowser.ControlSource = "=(""file:///C:/map-test.html"")" End Sub 

Then I tried the online version of the map - simply. JavaScript worked as expected and the Google Map interface loaded

 Private Sub Form_Current() Me.cWebBrowser.ControlSource = "=(""https://google-developers.appspot.com/maps/documentation/javascript/examples/map-simple"")" End Sub 

I tried to solve this problem for quite some time without success.

After this article http://support.microsoft.com/?kbid=315933 I turned on "My Computer Zone" in IE security settings

In all areas, I have included the following:

  • Allow Microsoft Web Browser Control Scripting
  • Active scripting

In the Advanced tab, I have included the following:

  • Allow running active content from CDs on my computer
  • Allow running active content in files on my computer

Someone suggested adding Mark of the Web to my pages, but that didn't help either.

I tried to clear the cache.

I tried to change the file name if the cache remained after cleaning.

map-test.html works when loaded in IE and WebBrowser Control, but only works locally using IE. What else could cause a problem other than the security setting? Is there a security setting I'm missing? Is there any other test I could do to diagnose the problem?

I'm crazy.

Environment:
Windows 7 64bit
Access 2010
IE 9

PS

The problem keeps getting weirder

Today I tried to create an extremely simple JavaScript page to make sure that the reason for this is not the Google Maps code.

 <!DOCTYPE html> <html> <body> <input type="button" onclick="alert('JavaScript Functioning');" value="Test JavaScript"> </body> </html> 

At first I worked, and I was delighted. Then I tried the Google Maps test page and it works too! So, I tried my full-featured map (working in IE and Firefox), which loads the JSON output from my DB application, and all this was confusing, the Google Maps code internally caused numerous errors (unfortunately, I did not document the errors).

Now I will return to the fourth; none of the pages allows you to create scripts, including 5 liners above?!?!

+4
source share
3 answers

First, see Enhanced Protected Mode and Local Files and Local Machine Lock Overview .

What works on my car

I tested different configurations using your same environment and they all work (see below for reservations).

  • Create a new form, add a webbrowser control to it:

  • Set your ControlSource for the url:

    enter image description here

  • Download the HTML and save it on your desktop, then access the local file in ControlSource works:

    enter image description here

  • Added a button and set the value of Webbrowser ControlSource within OnClick :

     Private Sub Command1_Click() WebBrowser0.ControlSource = "=""C:\Users\Renaud\Desktop\map-simple.htm""" End Sub 

enter image description hereenter image description hereenter image description here

Decision

From the links to the webpage security articles I mentioned above, I tried a few things:

  • If the file is saved in the temp user folder, it will load correctly.
    Try it, enter %TEMP% in Explorer and it will take you to C:\Users\username\AppData\Local\Temp or something like that.
    Save the html file there and try downloading it from Access, for example, using the button in the form above:

     Private Sub Command1_Click() WebBrowser0.ControlSource = "=""C:\Users\Renaud\AppData\Local\Temp\map-simple.htm""" End Sub 
  • Alternatively, in order for IE to allow you to open a file, you need to lower its integrity level so that it runs in the Internet zone when IE opens it (and therefore makes it work properly). You can check the current file settings by opening the command line (as administrator):

    ICACLS

    Now we can establish the integrity of the file and check the settings again:

    ICACLS

    Now you can open the file from Access and IE.

    Note that ACLs move with the file when you move them from an NTFS system to another NTFS system, but they can be lost if you copy them to a USB flash drive or other system formatted as FAT, for example for reuse on the target machine if they are lost.

  • I tried adding Mark Of The Web to the file itself, as Remou mentioned, but it does not work for me the file does not load.
    Here is what I tried:

     <!doctype html> <!-- saved from url=(0014)about:internet --> <html> <head> <title>Google Maps JavaScript API v3 Example: Map Simple</title> <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"> <meta charset="utf-8"> .... 
  • Another thing that should work is to try serving files from a local http server like Mongoose

+2
source

What works on my car

Purely for the sake of future readers.

Using Windows 7 and Access 2010 and the Webbrowser control in the toolbar, and not from additional ActiveX controls; using the code (below) from OP and adding Mark of the Web (MOTW) ; Using a * .html document saved on the desktop by setting the web browser control source to ="C:\Users\<user>\Desktop\java.htm" .

 <!DOCTYPE html> <!-- saved from url=(0023)http://www.contoso.com/ --> <html> <head> <title>Google Maps JavaScript API v3 Example: Map Simple</title> <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"> <meta charset="utf-8"> <style> html, body, #map_canvas { margin: 0; padding: 0; height: 100%; } </style> <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script> <script> var map; function initialize() { var mapOptions = { zoom: 8, center: new google.maps.LatLng(-34.397, 150.644), mapTypeId: google.maps.MapTypeId.ROADMAP }; map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions); } google.maps.event.addDomListener(window, 'load', initialize); </script> </head> <body> <input type="button" onclick="alert('JavaScript Functioning');" value="Test JavaScript"> <div id="map_canvas"></div> </body> </html> 
+2
source

I have used the WebBrowser control many times in access forms, with locally generated content.

For portability, I do not want to interfere with the security settings on each computer.

My solution is to use VBA instead of Javascript, for anything done locally. You can even bind VBA-based event handlers to document elements. (Use the Object Browser to learn the MSHTML library.)

This includes both files loaded with the file: // and on pages built using navigation: approximately: empty, and then with the content in WebBrowser.Document.Open/.Write.

For Google Maps, you can create a local document that hosts an Internet-based iframe. Security, Javascript will not work in a local document, but it should work in an iframe.

... Tom Robinson

0
source

Source: https://habr.com/ru/post/1445430/


All Articles