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

标签 javascript ruby-on-rails ruby-on-rails-4 heroku amazonads

我试图在 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.

如果我刷新页面,广告就会正常加载。这是来自亚马逊的广告代码,它位于 show.html.erb 文件中。

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

如果我使用带 iframe 代码的亚马逊广告没有问题,但这种格式的广告没有 iframe 选项(它是原生广告 - 扫描页面以获取相关内容以展示广告)

它是一个在 heroku 上启用了 turbolinks 的 Rails 4 站点。我完全不知道如何解决它。 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>

关于javascript - 错误 : It isn't possible to write into a document from an asynchronously-loaded external script,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40646588/

相关文章:

javascript - 无法调用类型缺少调用签名的表达式...没有兼容的调用签名

javascript - 客户端 JavaScript 中的 Stackoverflow "related entries"算法?

ruby-on-rails - has_and_belongs_to_many 关系的自定义 Active Admin 表单输入

javascript - 使用 Paperclip 通过 http 将图像发布请求上传到其他应用程序

javascript - 使用 nightwatch.js 按顺序调整测试

jquery - 如何从 Controller 调用 jQuery(从 Devise 注册路径后)?

javascript - 调用 Bootstrap 函数时为 "Uncaught TypeError: undefined is not a function"

ruby-on-rails - macOS 10.12 Sierra 上的 bundle 错误

css - "bootstrap-theme.css.map */": expected selector or at-rule, 之后无效的 CSS 是 "..."

javascript - 识别 Javascript 字符串中连续的十六进制字符 block