错误:无法从异步加载的外部脚本写入文档

Error: It isn't possible to write into a document from an asynchronously-loaded external script

本文关键字:脚本 外部 文档 加载 异步 错误      更新时间:2023-09-26

我试图在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上启用了涡轮链接。我完全不知道该如何修理它。adwords和media.net广告也是如此。

知道怎么解吗?

这个库可以解决您的问题https://github.com/krux/postscribe

异步编写javascript,即使使用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>