gpt4 book ai didi

javascript - Chrome 在 head 脚本完成之前显示 body

转载 作者:行者123 更新时间:2023-11-27 23:41:53 25 4
gpt4 key购买 nike

据我所知,浏览器应该在到达脚本时停止渲染 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/

25 4 0
文章推荐: javascript - 我在测试付款中收到错误消息 "Class ' Stripe' not found”
文章推荐: javascript - 如何使用 jQuery/JavaScript 通过用户输入更改
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com