is document.write blocking

一个人想着一个人 提交于 2019-12-07 21:26:28

问题


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.

Thanks for reading and thinking about it :)


回答1:


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.



来源:https://stackoverflow.com/questions/6585347/is-document-write-blocking

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!