用JavaScript实现让浏览器停止载入页面的方法

时间:2017-01-19    点击:111   

本想弄个判断页面载入时间,过长就不加载特效的JavaScript代码,不过还是有点缺陷,这里就记录下来吧。

IE浏览器用document.execCommand("Stop"),Chrome和Firefox用window.stop()(顺便说下,这是JavaScript标准中定义的方法),写在一起就是下面的方式了:

<html> 
<body> 
这里可以显示 
<script type="text/javascript"> 
if (window.stop) 
window.stop(); 
else 
document.execCommand("Stop"); 
</script> 
这里不能显示 
</body> 
</html>

当然,你也可以将JavaScript代码简写为:

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

很奇怪的是,如果写成下面的代码,Firefox不会停止载入:

<html> 
<body> 
这里可以显示 
<script type="text/javascript"> 
document.execCommand("Stop"); 
if (window.stop) 
window.stop(); 
</script> 
这里不能显示 
</body> 
</html>

此外,这种方式可以用来防止免费空间显示广告和被挂马。

一般只要把这段代码放在</html>后就行了。如果广告是在</body>前添加的,那就放在</body>前。

以上这篇用JavaScript实现让浏览器停止载入页面的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持本站。

AngularJs中 ng-repeat指令中实现含有自定义指令的动态html的方法
AngularJS 使用ng-repeat报错 [ngRepeat:dupes]
react.js 翻页插件实例代码
JavaScript自动点击链接 防止绕过浏览器访问的方法
创建一般js对象的几种方式
> 返回     
地址:上海市普陀区胶州路941号长久商务中心 电话: QQ:
© Copyright 2012 上海网络 Product All Rights Reserved