2

我想以阻塞方式将脚本插入页面(不幸的是,不能使用脚本标签的 src 属性)。如果我在所有浏览器上通过 document.write() 插入标签,它会阻塞吗?我知道这是一种不好的做事方式,但我真的需要它来阻止其他资源的加载。目前我正在做:

document.getElementsByTagName('head')[0].appendChild(dynamic_script_tag_created_previously);

但这并不好,因为它是异步负载。

感谢您阅读和思考:)

4

1 回答 1

1

是的,例如:

<script>
document.write('<!doctype html><html id="sanitized"><head>'
+ document.head.innerHTML + '</head><body>'
+ document.body.innerHTML + '</body></html>');
</script>

将锁定浏览器几秒钟。

于 2014-03-25T18:17:32.853 回答