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

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

问题描述

在加载页面的过程中,是否有一种javascript停止iframe的方法?我需要这样做的原因是我有一个来自Web服务器的背景iframe流式传输数据(通过Comet风格机制),我需要能够随意切断连接。


$ b $

解决方案

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

  window.frames [0] .stop()

对于IE,您可以使用document.execCommand('Stop')执行相同的操作:

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

可以使用的跨浏览器解决方案:

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


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.

Any ideas welcome.

解决方案

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

window.frames[0].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();
}

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

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