如何从返回document.write()的URL异步显示数据? [英] How to show data asynchronously from URL that return document.write()?

查看:188
本文介绍了如何从返回document.write()的URL异步显示数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用一个第三方应用程序,该应用程序提供了Javascript代码,该代码使用document.write()方法返回数据.即

We are using a 3rd Party application that provides Javascript code that returns the data using document.write() method. i.e.,

<script src="//demoUrl.com/response/" type="text/javascript"></script>

此URL上显示的数据如下:

The data shown on this URL is like this:

document.write('This is the output');

因此,当我们按原样使用此脚本时,此过程可以正常工作,但是当在此script标签上添加async或defer属性时,则不会显示输出.

So, this process works fine when we use this script as it is, but when we add async or defer attribute on this script tag, the output does not show.

我们如何异步显示数据,从而不会停止页面加载?

How we can show the data asynchronously so it did not stop the page load?

推荐答案

说服第三方重写脚本,使其不使用document.write,因为它与延迟执行完全不兼容.

Persuade the third party to rewrite the script so it doesn't use document.write as it is entirely incompatible with delayed execution.

请参见 MDN文档:

请勿从异步脚本调用document.write().在Firefox 3.6中,调用document.write()会产生不可预期的影响.在Firefox 4中,从异步脚本调用document.write()无效(除了在错误控制台上打印警告).

Never call document.write() from an async script. In Firefox 3.6, calling document.write() has an unpredictable effect. In Firefox 4, calling document.write() from an async script has no effect (other than printing a warning to the error console).

这篇关于如何从返回document.write()的URL异步显示数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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