Error: cannot write to document from asynchronously loaded external script

I try to upload ads to the 4 rails website and keep getting the following error

onejs?MarketPlace=US&adInstanceId=xxxxxxxx&storeId=xxxxxxx:1 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. 

If I refresh the page, the ad loads just fine. Here is the ad code from amazon, which is located in the show.html.erb file.

 <script src="//z-na.amazon-adsystem.com/widgets/onejs?MarketPlace=US&adInstanceId=xxxxxxxxx&storeId=xxxxxxxx"></script> 

If I use amazon ads with Iframe code, there is no problem, but there is no iframe option in this format (it is designed to view ads based on relevant ads)

His site of 4 rails with turbolinks is included on the hero. I have a complete loss of how to fix this. This also happens with adwords and media.net ads.

Any idea how to solve?

+6
source share
1 answer

This library can solve your problem https://github.com/krux/postscribe

Write javascript asynchronously, even with document.write.

 <div id="ad"><h5>Advertisement</h5></div> <script type="text/javascript"> // jQuery used as an example of delaying until load. $(function() { // Build url params and make the ad call postscribe('#ad', '<script src=doubleclick_url_with_params><\/script>'); }); </script> 
+10
source

Source: https://habr.com/ru/post/1012396/


All Articles