警告:从异步加载的外部脚本对document.write()的调用被忽略。这是如何修复的? [英] Warning: A call to document.write() from an asynchronously-loaded external script was ignored. How is this fixed?

查看:994
本文介绍了警告:从异步加载的外部脚本对document.write()的调用被忽略。这是如何修复的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Ruby on Rails应用程序中,我使用 Facebox插件获取Ajax弹出窗口。我有2页称为 add_retail_stores / new.html.erb add_retail_stores / new.js new.js 页面继承了 new.html.erb 页面中的所有元素,因此看起来完全相似。我在HTML页面上有一个Google地图脚本,它应该可以正常工作。但是在我的不同页面上弹出的 new.js 页面名为 add_store_prices.html.erb 页面(<%= link_to add_retail_store_path,:remote => true%>
$ b 我得到错误:


警告:从异步加载的外部脚本对document.write()的调用被忽略。
源文件: http:// localhost:3000 / add_store_prices
行:0


我相信是因为它试图通过2个函数/脚本。第一个用于Facebox,然后是Google脚本。任何人都知道如何处理这个错误?



编辑:



我相信Facebox插件使用 document.write 但我不确定在哪里,也许在我的页面上这两行中的一行?

新.js:

  $。facebox('<%= escape_javascript(render:template =>'business_retail_stores /new.html')%>')
$('#facebox form')。data('remote','true');


解决方案

不要使用document.write。脚本异步加载,这意味着它从文档解析状态中分离。 JS引擎完全没有办法知道哪里的document.write应该在页面中执行。

外部脚本可以立即加载,并且document.write执行< script src =...> 标签,或者它可能会打到net.burp并在一小时后加载,这意味着document.write在页面末尾被标记。这实际上是一种竞争条件,所以JS引擎会忽略异步加载的脚本中的document.writes。



将document.write转换为使用常规DOM操作,并由 document.onload 类型处理程序。


In my Ruby on Rails application I am using the Facebox plugin for an Ajax pop up window. I have 2 pages called add_retail_stores/new.html.erb and add_retail_stores/new.js. The new.js page inherits all elements from the new.html.erb page so it looks exactly alike. I have a Google map script on the HTML page that works as it should. But the new.js page that pops up on my different page called add_store_prices.html.erb page(<%= link_to add_retail_store_path, :remote => true %>)

I get the error:

Warning: A call to document.write() from an asynchronously-loaded external script was ignored. Source File: http://localhost:3000/add_store_prices Line: 0

I believe because it's trying to go through 2 functions/scripts. The first one for the Facebox and then the Google script. Anyone know how to handle this error?

EDIT:

I believe the Facebox plugin is using document.write but I am not sure where, perhaps in one of these 2 lines on my page?

new.js:

$.facebox('<%= escape_javascript(render :template => 'business_retail_stores/new.html') %>')
$('#facebox form').data('remote','true');

解决方案

Don't use document.write. The script is being loaded asynchronously, which means it's detached from the document parsing state. There is quite literally NO WAY for the JS engine to know WHERE the document.write should be executed in the page.

The external script could load instantaneously and the document.write executes where the <script src="..."> tag is, or it could hit a net.burp and load an hour later, which means the document.write gets tagged at the end of the page. It's quite literally a race condition, so JS engines will ignore document.writes from scripts loaded asynchronously.

Convert the document.write to use regular DOM operations, guarded by a document.onload type handler.

这篇关于警告:从异步加载的外部脚本对document.write()的调用被忽略。这是如何修复的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆