简体   繁体   English

如何检测是否通过javascript在浏览器中按下停止加载按钮?

[英]How to detect if stop loading button pressed in browser via javascript?

如何检测是否通过javascript在浏览器中按下停止加载按钮,或者页面是否仍在加载?

Assuming the script reaches the browser and not stop executing if the "stop loading button" is pressed, this might be a viable option 假设脚本到达浏览器并且如果按下“停止加载按钮”则不会停止执行,这可能是一个可行的选择

Using this can still have non loaded resources, though will give you a good start. 使用它仍然可以有非加载资源,但会给你一个良好的开端。

 <!DOCTYPE html> <html> <head> <meta http-equiv='content-type' content='text/html; charset=UTF-8' /> <script type='text/javascript'> var DomLoaded = { done: false, onload: [], loaded: function() { if (DomLoaded.done) return; DomLoaded.done = true; if (document.removeEventListener) { document.removeEventListener('DOMContentLoaded', DomLoaded.loaded, false); } for (i = 0; i < DomLoaded.onload.length; i++) DomLoaded.onload[i](); }, load: function(fireThis) { this.onload.push(fireThis); if (document.addEventListener) { document.addEventListener('DOMContentLoaded', DomLoaded.loaded, false); } else { /*IE<=8*/ if (/MSIE/i.test(navigator.userAgent) && !window.opera) { (function() { try { document.body.doScroll('up'); return DomLoaded.loaded(); } catch (e) {} if (/loaded|complete/.test(document.readyState)) return DomLoaded.loaded(); if (!DomLoaded.done) setTimeout(arguments.callee, 10); })(); } } /* fallback */ window.onload = DomLoaded.loaded; } }; DomLoaded.load(function() { var d = document; if (d.getElementsById('loaded-checker')) { // loaded } else { // not loaded } }); </script> <link rel='stylesheet' type='text/css' href='/css/style.css' /> <script src="/js/script.js"></script> </head> <body> <div class="main-header"></div> <div class="main-content"></div> <div class="main-footer"></div> <div id="loaded-checker"></div> </body> </html> 

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

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