none
Failed to execute 'write' on 'Document': It isn't possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened RRS feed

  • Question

  • Hi, I am getting the following error at random when trying to register the ShapeToolboxModule:

    Failed to execute 'write' on 'Document': It isn't possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened

    which is being thrown at: mapcontrol.ashx?v=7.0:1

    I register the module as follows:

    Microsoft.Maps.registerModule("ShapeToolboxModule", "/app/lib/bingmodules/ShapeToolboxModule.js");
    Microsoft.Maps.loadModule("ShapeToolboxModule", { callback: ShapeToolboxModuleLoaded });

    I have no idea why this is happening as I have previously loaded other modules successfully.

    Has anybody encountered this error before?


    Cbr600rr

    Friday, September 12, 2014 9:36 AM

Answers

  • Ah... looking into this it appears to be a new security setting in some browsers. In the shape drawing module there is code that adds some HTML to the page. Apparently dynamically loaded JavaScript files are not allowed to write to the page anymore in some browsers. To get around this add a normal script reference on your page that points the Shape toolbox module.

    http://rbrundritt.wordpress.com

    Friday, September 12, 2014 10:53 AM
  • Now that I think about it, most of the modules write to the DOM without any issues. There must be something else going on in your application as this is the first time I've come across this issue and I know of lots of people who are using the drawing tools without any issues and are on the latest versions of browsers. Try doing a search for the error message. This is a general JavaScript/HTML thing and not specific to Bing Maps. There are a bunch of solutions out there.


    http://rbrundritt.wordpress.com


    Friday, September 12, 2014 11:27 AM
  • For some weird reason this works:

    $(document).ready(function () {
        $.getScript("lib/bingmodules/ShapeToolboxModule.js", function () {
            Microsoft.Maps.registerModule("ShapeToolboxModule", "lib/bingmodules/ShapeToolboxModule.js");
        });
    });


    Cbr600rr

    • Marked as answer by Ricky_Brundritt Thursday, September 18, 2014 11:23 AM
    Friday, September 12, 2014 11:54 AM

All replies

  • Are you registering/loading this module after loading the map? If not it's likely that this line of code is firing before the page is fully rendered.

    http://rbrundritt.wordpress.com

    Friday, September 12, 2014 9:59 AM
  • Yes, I am loading after loading the map.

    Straight after: var map= new Microsoft.Maps.Map(elem, options);

    Where else can I register/load the module?


    Cbr600rr

    Friday, September 12, 2014 10:43 AM
  • Ah... looking into this it appears to be a new security setting in some browsers. In the shape drawing module there is code that adds some HTML to the page. Apparently dynamically loaded JavaScript files are not allowed to write to the page anymore in some browsers. To get around this add a normal script reference on your page that points the Shape toolbox module.

    http://rbrundritt.wordpress.com

    Friday, September 12, 2014 10:53 AM
  • Unfortunately I cannot do that. I use RequireJS to load all my libraries (modules). This means loading the ShapeToolBox module using RequireJS will cause the same error because it's in RequireJS nature to loads js files dynamically.

    If I try to load it normally with a script tag in the html page, it will load too quick, meaning it will load before the Bing Map library loads because Bing is being loaded by RequireJS.

    Hope this makes sense.


    Cbr600rr

    Friday, September 12, 2014 11:02 AM
  • Now that I think about it, most of the modules write to the DOM without any issues. There must be something else going on in your application as this is the first time I've come across this issue and I know of lots of people who are using the drawing tools without any issues and are on the latest versions of browsers. Try doing a search for the error message. This is a general JavaScript/HTML thing and not specific to Bing Maps. There are a bunch of solutions out there.


    http://rbrundritt.wordpress.com


    Friday, September 12, 2014 11:27 AM
  • For some weird reason this works:

    $(document).ready(function () {
        $.getScript("lib/bingmodules/ShapeToolboxModule.js", function () {
            Microsoft.Maps.registerModule("ShapeToolboxModule", "lib/bingmodules/ShapeToolboxModule.js");
        });
    });


    Cbr600rr

    • Marked as answer by Ricky_Brundritt Thursday, September 18, 2014 11:23 AM
    Friday, September 12, 2014 11:54 AM