据我所知,浏览器应该在到达脚本时停止渲染 DOM,直到脚本完成。
但是,如果我写一个
window.open('Mypage.aspx?ID=0', '_top');
在新页面打开之前,我仍然可以在 head 标签处看到快速的“闪烁”。 我什至试图在 body 标签之前人为地创建一个延迟,但无济于事。 我怎样才能避免这种闪烁?
例子:
<html>
<head>
<title>aa</title>
<script type="text/javascript">window.open('MyPage.aspx?ID=0', '_top');
var now = new Date().getTime();
while(new Date().getTime() < now + 3000){ /* force delay */ }
</script></head><body style="background-color:red">
initial page
</body>
最佳答案
在 Chrome 中,您可以在脚本的第一行使用 window.stop();
来停止 html 渲染。
尽管对我来说,使用 css 类来管理它以在适当的时候隐藏/显示它似乎更一致。
关于javascript - Chrome 在 head 脚本完成之前显示 body,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31383502/