是document.write阻止 [英] is document.write blocking

查看:190
本文介绍了是document.write阻止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I would like to insert a script into the page in a blocking way (can't use the src attribute of a script tag unfortunately). Would it block if i inserted the tag via document.write() on all browsers? I know this is a bad way of doing things, but i really need it to block the loading of other resources. Currently i'm doing:

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

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

But this is not good since it's an asynchroneous load.

感谢阅读和思考:)

推荐答案

是的,例如:

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

将锁定浏览器几秒钟。

这篇关于是document.write阻止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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