HTML isn't outputting

HTML isn't outputting

James

A Verified Legend
Gold Member
Local time
17:01
Joined
Oct 13, 2019
Messages
49

Hi,

We're trying to output a script, it's below:

JavaScript:
prdom.query('#belowimage').html('<div id="chasethetrend_300x250_320x50_320x100"><script type="text/javascript">freestar.queue.push(function(){freestar.newAdSlots({placementName: "chasethetrend_300x250_320x50_320x100", slotId: "chasethetrend_300x250_320x50_320x100"});});</script></div>');

An engineer has told us, this script won't work because, he said:

Hey James,

Apologies for the delay here. We had a couple of all-hands-on-deck situations yesterday and I didn't get a chance to look at this by EOD. I did however check out both of the links just now and the issue is related to the script itself. In both instances the noad event is working as intended and dropping your code on the page. The reason the first instance works is you're actively modifying the DOM via the ".html()" method. In the second, you're using document.write(). The latter does not work because you're not able to use document.write() from async scripts after the page has already loaded. You can note this yourself by checking out the console errors. You should see one in yellow referencing the event.

You can still use scripts to modify the DOM via the noad, you would just need to be explicit in what you're doing and use more specific javascript methods. Here is a link to a StackOverflow thread that goes into this with a little more details. Happy to shed further light personally if you have additional questions as well.


Any idea of how we can implement the suggestion?

 

Mike Rees

Member
Local time
17:01
Joined
Feb 3, 2020
Messages
67

Is it necessary to insert the script in this manner? Is this to circumvent ad blockers?

That said, the recommendation they've given you appears to be to avoid using document.write(). The accepted solution in the SO article implies that a direct swap of your current code would be:

JavaScript:
var targetElement = document.getElementById('belowImage')
targetElement.innerHTML = '<div id="chasethetrend_300x250_320x50_320x100"><script type="text/javascript">freestar.queue.push(function(){freestar.newAdSlots({placementName: "chasethetrend_300x250_320x50_320x100", slotId: "chasethetrend_300x250_320x50_320x100"});});</script></div>';

I can't say for sure whether that will work or not but failing that one of the comments suggested using postscribe which has your specific use case in its readme.

 

James

A Verified Legend
Gold Member
Local time
17:01
Joined
Oct 13, 2019
Messages
49

Is it necessary to insert the script in this manner? Is this to circumvent ad blockers?

That said, the recommendation they've given you appears to be to avoid using document.write(). The accepted solution in the SO article implies that a direct swap of your current code would be:

JavaScript:
var targetElement = document.getElementById('belowImage')
targetElement.innerHTML = '<div id="chasethetrend_300x250_320x50_320x100"><script type="text/javascript">freestar.queue.push(function(){freestar.newAdSlots({placementName: "chasethetrend_300x250_320x50_320x100", slotId: "chasethetrend_300x250_320x50_320x100"});});</script></div>';

I can't say for sure whether that will work or not but failing that one of the comments suggested using postscribe which has your specific use case in its readme.

Thanks Mike - I’ll give this a try.

 
Top