开发者

is document.write blocking

开发者 https://www.devze.com 2023-03-17 23:34 出处:网络
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 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 d开发者_如何学Coing:

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

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

Thanks for reading and thinking about it :)


Yes, for example:

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

Will lock up the browser for a few seconds.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号