使用 javascript 停止 iframe 加载页面 [英] Stopping a iframe from loading a page using javascript

查看:41
本文介绍了使用 javascript 停止 iframe 加载页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

javascript 中有没有办法在加载页面的过程中停止 iframe?我需要这样做的原因是我有一个来自 Web 服务器的后台 iframe 流数据(通过 Comet 风格的机制),我需要能够随意切断连接.

Is there a way in javascript of stopping an iframe in the middle of loading a page? The reason I need to do this is I have a background iframe streaming data from a web server (via a Comet style mechanism) and I need to be able to sever the connection at will.

欢迎提出任何想法.

推荐答案

对于 FireFox/Safari/Chrome 你可以使用 window.stop():

For FireFox/Safari/Chrome you can use window.stop():

window.frames[0].stop()

对于 IE,你可以用 document.execCommand('Stop') 做同样的事情:

For IE, you can do the same thing with document.execCommand('Stop'):

window.frames[0].document.execCommand('Stop')

对于跨浏览器解决方案,您可以使用:

For a cross-browser solution you could use:

if (navigator.appName == 'Microsoft Internet Explorer') {
  window.frames[0].document.execCommand('Stop');
} else {
  window.frames[0].stop();
}

这篇关于使用 javascript 停止 iframe 加载页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆