如何确定 document.write() 是否会覆盖页面,即当前脚本是否异步加载

How to determine if document.write() will overwrite the page, i.e. if current script's been loaded asynchronously?

本文关键字:是否 加载 异步 脚本 覆盖 write document 何确定      更新时间:2023-09-26

如果在加载页面后调用document.write(),整个页面将被覆盖。例如,当对document.write()的调用放置在异步加载的脚本中时,可能会发生这种情况。是否有可能在剧本中找出情况是否确实如此,而无需完全辞职document.write()

if (document.readyState === "complete")

这将检查 DOM 是否已完成加载...