简体   繁体   English

为什么我的页面会在刷新期间在Chrome中触发“就绪”事件?

[英]Why does my page fire “ready” event in Chrome during refresh?

I have an HTML like this: 我有这样的HTML:

<!-- simulate a slow-loading request -->
<script src="http://example.com:81/non-existent-script.js"></script>

<script>
    $(document).ready(function() { alert("ready"); })
</script>

(see http://jsfiddle.net/mK63F/ ) (见http://jsfiddle.net/mK63F/

When I open the page in Chrome, the example.com request should hang - but then, when I hit F5, the "ready" alert appears, before the page refreshes. 当我在Chrome中打开页面时, example.com请求应该挂起 - 但是当我点击F5时,会页面刷新之前显示“就绪”警报。 Why does that happen? 为什么会这样? And how to distinguish that situation (ie refresh during page load) from "normal" page ready? 如何区分这种情况(即页面加载期间刷新)和“正常”页面准备好了?

When you click f5 browser stops all active requests and ready function is ruining Because everything is loaded ... 当你点击f5浏览器停止所有活动请求和ready功能正在破坏因为一切都已加载...

alternative is 替代方案是

$( window ).load(function() {
  alert("loaded");
});

http://jsfiddle.net/26x2K/4/ http://jsfiddle.net/26x2K/4/


LINK HERE 链接在这里

.load not running if all request dont get the success responce 如果所有请求都没有得到成功响应,则.load不会运行

Also Read - jquery what are differences between document ready and window load 另外阅读 - jquery文档就绪和窗口加载之间的区别是什么

When you hit F5 for reload the request gets canceld. 当您点击F5进行重新加载时,请求会被取消。 You can see this in devtools with status canceld: 你可以在状态为canceld的devtools中看到这个:

在此输入图像描述

Therefore the document is ready because no requests are loading anymore. 因此,文档已准备就绪,因为不再加载任何请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM