gpt4 book ai didi

javascript - 如何从返回 document.write() 的 URL 异步显示数据?

转载 作者:行者123 更新时间:2023-12-03 00:42:33 24 4
gpt4 key购买 nike

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

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

此 URL 上显示的数据如下:

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

所以,当我们按原样使用这个脚本时,这个过程工作得很好,但是当我们添加 async 时,这个过程就可以正常工作。或此脚本标记上的 defer 属性,输出不会显示。

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

最佳答案

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

参见the MDN documentation :

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).

关于javascript - 如何从返回 document.write() 的 URL 异步显示数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53391473/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com