How to detect if stop loading button pressed in browser via javascript or if page is still loading?
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With