1

I am getting this error with my code "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."

I am trying to load every 25 seconds new ad banner from third site.

mFl();
function mFl() {
  if (document.getElementsByClassName('adposition').length > 0) {   loadMe("adposition","http://third.tld/b?z=1&u=a&width=728&height=90");   }  
  setTimeout(mFl, 25000);
}

function loadMe(className, scriptName) {
  var docHeadObj = document.getElementsByClassName( className )[0];
  docHeadObj.innerHTML = "";
  var ttt = Math.floor(Date.now() / 1000);
  var dynamicScript = document.createElement("script");
  dynamicScript.type = "text/javascript";
  dynamicScript.src = scriptName+ "&uunique=" + ttt;
  docHeadObj.appendChild(dynamicScript);
}

Any workaround for this please?

peter
  • 4,289
  • 12
  • 44
  • 67

1 Answers1

1

Try using https://github.com/krux/postscribe plugin. As it mentioned in the repo.

Remote scripts, especially ads, block the page from doing anything else while they load. They contribute a large % to load times which affects your bottom line. Asynchronous ads do not block the page and can be delivered after core content - Async FTW.

Why is it so hard to deliver ads asynchronously? Because they may contain calls to document.write, which expects to be handled synchronously. PostScribe lets you deliver a synchronous ad asynchronously without modifying the ad code.

John
  • 1,489
  • 9
  • 17