编程语言
首页 > 编程语言> > javascript – document.write的所有邪恶是什么

javascript – document.write的所有邪恶是什么

作者:互联网

我知道使用document.write有很多问题,我绝对避免使用它.但是,我遇到了使用它的第三方窗口小部件的问题.我不太清楚如何言语(也可能不知道所有的原因)为什么应该避免这一小片纯粹的邪恶.

我已经重写了第三方提供的代码内联其小部件的代码,以便它不使用document.write.但是,该代码会加载另一个使用它的脚本.我正在推迟加载脚本,这会导致在onload之后发生document.write调用,覆盖整个页面.

所以问题是,使用document.write的所有问题是什么,以便我可以提供一个关于第三方应该修复代码的原因的综合列表?

先感谢您!

解决方法:

引自following post

  • Because inline scripts force user’s browser to wait for the code to
    complete (even if we have to wait for an external url to load) before
    rendering the rest of page.

  • Because we can’t further process (modify/duplicate etc) the output
    before embedding it in the actual webpage.

  • Also they bloat the xhtml code

标签:javascript,document-write
来源: https://codeday.me/bug/20190530/1185987.html