Dynamically adding leadbolt ads - Failed to execute 'write' on 'Document'

214 views Asked by At

So I have this function:

function ads(argument0)
{
    var div=document.createElement("div");
    div.id="ads";
    div.style.display="none";
    div.style.zIndex="1";
    div.style.position="fixed";
    document.getElementById("gm4html5_div_id").insertBefore(div,document.getElementById("canvas")); 
    var script=document.createElement("script");
    script.type="text/javascript";
    script.src=argument0;
    div.appendChild(script);
}

argument0 being the link to the ad script.

Problem is, when running it I get this error:

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've seen a few topics here, but unfortunately none of them helped me. My question is, what would I need to do or add so the external script gets executed?

Please note, I only know enough js to get by.

1

There are 1 answers

0
Quentin Kerguélen On

If you're using Adwords for the ads, it looks that Google provide a fix to this issue. First you have to implement the conversion_async.js from googleadservices.com : just add this to your head:

<script type="text/javascript" src="http://www.googleadservices.com/pagead/conversion_async.js" charset="utf-    8"></script>

then fire the asynchronous AdWords Remarketing Tag can be fired on page load by calling the google_trackConversion function like this:

<script type="text/javascript">
/* <![CDATA[ */
window.google_trackConversion({
  google_conversion_id: 123456789, 
  google_custom_params: {
    parameter1: 'abc123', 
    parameter2: 29.99
  },
  google_remarketing_only: true
});
//]]>
</script>

You can read the full doc here: https://developers.google.com/adwords-remarketing-tag/asynchronous/