我刚遇到 window.stop()
The stop() method is exactly equivalent to clicking the stop button in the browser. Because of the order in which scripts are loaded, the stop() method cannot stop the document in which it is contained from loading, but it will stop the loading of large images, new windows, and other objects whose loading is deferred. https://developer.mozilla.org/en-US/docs/Web/API/Window.stop
我在想:
- “窗口”和“延迟加载的其他对象”指的是什么?有人可以给我一个实际的例子吗?
- 如果我将图像附加到正文并在加载 30% 时调用
window.stop()
,然后在稍后附加相同的图像;后一张图片是否只有 70% 的剩余负载?
最佳答案
What do 'windows' and 'other objects whose loading is deffered' refer to? Can somebody give me a practical example?
新窗口可以是 iframe 或常规框架。脚本本身可以标记为 defer
,它在文档之后和其他内联脚本之后加载它们,因此也可以使用 window.stop()
停止它们。因此,可能会停止加载的对象的实际示例包括:iframe、嵌入式对象(如 Adobe Flash)、标记为 defer
的脚本和图像。这里的想法是,如果您要从页面中的脚本调用 window.stop()
,它只能应用于尚未完成加载的资源。根据定义,至少部分文档和您的脚本已经完成加载,否则脚本不会运行,因此您可以调用 window.stop()
所以它主要应用于资源稍后在加载过程中加载,例如上面的那些。
If I append an image to the body and call window.stop() when 30% has been loaded, and then append the same image at a later time; will the latter image only have 70% left load?
浏览器缓存不太可能缓存图像的 30%,然后在您下次请求该资源时仅恢复加载剩余的 70%。大多数缓存只是拒绝缓存未完全加载的对象。在任何情况下,这都完全取决于浏览器,因为这种类型的缓存行为超出了标准。
关于javascript - 有关 window.stop() 的详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23481364/