我试图在rails 4网站上加载广告并继续收到以下错误
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.
如果我刷新页面广告加载就好了.以下是来自amazon的广告代码,该代码位于show.html.erb文件中.
<script src="//z-na.amazon-adsystem.com/widgets/onejs?MarketPlace=US&adInstanceId=xxxxxxxxx&storeId=xxxxxxxx"></script>
如果我使用带有iframe代码的亚马逊广告没有问题,但此格式广告没有iframe选项(这是原生广告 – 扫描相关内容的页面以展示广告)
它是一个rails 4站点,在heroku上启用了turbolinks.我完全不知道如何解决它.这也发生在adwords和media.net广告上.
知道怎么解决?
解决方法
该库可能会解决您的问题
https://github.com/krux/postscribe
Asynchronously write javascript,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>