Using JavaScript to realize the method of letting browser stop loading pages

  • 2021-07-12 05:19:16
  • OfStack

Want to get a judgment page loading time, too long will not load special effects of JavaScript code, but still a bit flawed, here on record it.

The IE browser uses document. execCommand ("Stop"), Chrome and Firefox use window. stop () (by the way, this is the method defined in the JavaScript standard), and it is written in the following way from 1:


<html> 
<body> 
 Here you can display  
<script type="text/javascript"> 
if (window.stop) 
window.stop(); 
else 
document.execCommand("Stop"); 
</script> 
 Can't be displayed here  
</body> 
</html>

Of course, you can also shorten the JavaScript code to:


window.stop ? window.stop() : document.execCommand("Stop");

Strangely enough, Firefox won't stop loading if you write the following code:


<html> 
<body> 
 Here you can display  
<script type="text/javascript"> 
document.execCommand("Stop"); 
if (window.stop) 
window.stop(); 
</script> 
 Can't be displayed here  
</body> 
</html>

In addition, this method can be used to prevent free space from displaying advertisements and being hung by horses.

1. Just put this code in the < /html > Just after that. If the advertisement is in < /body > If you add it before, put it in < /body > Front.


Related articles: