Asynchronously-loaded external script was ignored

  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9089
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Wondering if anybody knows of a solution here for a script I am trying to load asynchronously. It actually works okay in Internet Explorer 8, but not in Firefox or Chrome. The error I am getting in Firefox is:

Quote:
a call to document.write() from an asynchronously-loaded external script was ignored


So if I load it asynchronously then I get that error which prevents it from working properly. Here is the example I am using:

HTML Code: [ Select ]
<div id="MarketGid4770"></div>
<script type="text/javascript">
(function() {
   var MarketGidDate = new Date();
   var mg = document.createElement('script');
   mg.type = 'text/javascript';
   mg.async = true;
   mg.src = 'http://jsn.dt07.net/o/z/ozzu.com.4770.js?t='+MarketGidDate.getYear()+MarketGidDate.getMonth();
   var g = document.getElementsByTagName('script')[0];
   g.parentNode.insertBefore(mg, g);
})();
</script>
  1. <div id="MarketGid4770"></div>
  2. <script type="text/javascript">
  3. (function() {
  4.    var MarketGidDate = new Date();
  5.    var mg = document.createElement('script');
  6.    mg.type = 'text/javascript';
  7.    mg.async = true;
  8.    mg.src = 'http://jsn.dt07.net/o/z/ozzu.com.4770.js?t='+MarketGidDate.getYear()+MarketGidDate.getMonth();
  9.    var g = document.getElementsByTagName('script')[0];
  10.    g.parentNode.insertBefore(mg, g);
  11. })();
  12. </script>


When I loaded it the other way this works:

HTML Code: [ Select ]
<div id="MarketGid4770"></div>
<script type="text/javascript">
var MarketGidDate = new Date();
document.write('<scr'+'ipt type="text/javascript" '+'src="http://jsn.dt07.net/o/z/ozzu.com.4770.js?t='+MarketGidDate.getYear()+MarketGidDate.getMonth()+'" charset="utf-8" ></scr'+'ipt>');
</script>
  1. <div id="MarketGid4770"></div>
  2. <script type="text/javascript">
  3. var MarketGidDate = new Date();
  4. document.write('<scr'+'ipt type="text/javascript" '+'src="http://jsn.dt07.net/o/z/ozzu.com.4770.js?t='+MarketGidDate.getYear()+MarketGidDate.getMonth()+'" charset="utf-8" ></scr'+'ipt>');
  5. </script>


Any ideas why that error is being thrown, is there any particular security reason why it would be ignored for asynchronously loaded external scripts?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9089
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

I looked into that more and found that calls to document.write() or document.writeln() are ignored after the page load event has been handled. I am thinking that the only way to get this to work properly is for the 3rd party script to update their code to work with the DOM itself instead of using the Javascript write function to insert the content. If anybody else has ideas that would be great, I may just end up placing this in an iframe for a workaround, but I would prefer not doing that.
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

I'm guessing that having your server load it in the background, parsing it, and sending it to the visitor, proxy-style is out of the question. It'd work, but I get the feeling this 3rd party wouldn't like it.

Other than that, I'm thinking the same things you are. <iframe> it until they break down and update their code.
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

Is there no way you can write a new script tag to the DOM?

Ha! Yes I thought I read something about the previously. Perhaps this will give some fresh ideas?

http://www.west-wind.com/weblog/posts/107136.aspx

HTH

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 138 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.