相关疑难解决方法(0)

async使用document.write加载javascript

我试图异步谷歌地图api javascript.

因此,正常的脚本标记有效 <script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>

但是,以下异步版本没有.

(function () {
    var gmap = document.createElement('script'); gmap.type = 'text/javascript'; gmap.async = true;
    gmap.src = 'https://maps.googleapis.com/maps/api/js?sensor=false';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(gmap, s);
})();
Run Code Online (Sandbox Code Playgroud)

经过一些断点+检查操作后,我发现该行在异步模式下无法正常运行.

document.write('<' + 'script src="' + src + '"' + 
' type="text/javascript"><' + '/script>');
Run Code Online (Sandbox Code Playgroud)

同步模式下的文档对象是"HTMLDocument",但在异步模式下则是"#document".加载页面后,文档对象发生了某些变化.思考?

干杯.

更新:这个问题更多的是为什么不会触发document.write而不是异步加载谷歌地图API.如果在此行上设置断点,则可以看到document.write函数存在.这与document.write是本机的这一事实有什么关系吗?

javascript asynchronous google-maps-api-3

11
推荐指数
2
解决办法
2万
查看次数

调用document.write()

此代码不起作用:

<div class="pix"><div id="addTimestamp"></div></div>
<script type="text/javascript">
(function () {
    var date = new Date(), 
        timestamp = date.getTime(),
        newScript = document.createElement("script");

    newScript.type = 'text/javascript';
    newScript.src = 'someUrl=' + timestamp + '?';
    document.getElementById('addTimestamp').appendChild(newScript);
}())
</script>
Run Code Online (Sandbox Code Playgroud)

动态脚本添加document.write(someCode which loads banners).但在Firebug中我有一个错误:

从异步加载的外部脚本调用document.write()被忽略.

javascript document.write

5
推荐指数
1
解决办法
2036
查看次数

警告:忽略了从异步加载的外部脚本调用document.write().这是如何解决的?

在我的Ruby on Rails应用程序中,我使用Facebox插件进行Ajax弹出窗口.我有2页叫做add_retail_stores/new.html.erbadd_retail_stores/new.js.该new.js页面继承了new.html.erb页面中的所有元素,因此它看起来完全相同.我在HTML页面上有一个Google地图脚本,可以正常工作.但是new.js在我的不同页面上弹出的页面叫做add_store_prices.html.erbpage(<%= link_to add_retail_store_path, :remote => true %>)

我收到错误:

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

我相信因为它试图通过2个函数/脚本.第一个是Facebox,然后是Google脚本.有谁知道如何处理这个错误?

编辑:

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

new.js:

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

javascript google-maps ruby-on-rails facebox

4
推荐指数
1
解决办法
2万
查看次数