Asynchronously-loaded external script was ignored

  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Joined: Dec 20, 2002
  • Posts: 8934
  • Loc: Seattle, WA & Phoenix, AZ
  • Status: Offline

Post March 28th, 2011, 11:28 am

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?
Ozzu Hosting - Want your website on a fast server like Ozzu?
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post March 28th, 2011, 11:28 am

  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Joined: Dec 20, 2002
  • Posts: 8934
  • Loc: Seattle, WA & Phoenix, AZ
  • Status: Offline

Post March 28th, 2011, 11:59 am

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.
Ozzu Hosting - Want your website on a fast server like Ozzu?
  • joebert
  • Sledgehammer
  • Genius
  • No Avatar
  • Joined: Feb 10, 2004
  • Posts: 13458
  • Loc: Florida
  • Status: Offline

Post March 28th, 2011, 2:22 pm

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.
Strong with this one, the sudo is.
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Joined: May 21, 2004
  • Posts: 3229
  • Loc: South Africa
  • Status: Offline

Post April 24th, 2011, 12:49 pm

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
Watch me grow

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 140 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
 
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.