javascript中有没有一种方法可以在加载页面的过程中停止iframe?我需要这样做的原因是我有一个后台iframe流数据从web服务器(通过Comet风格的机制),我需要能够随意切断连接。
欢迎任何想法。
发布于 2010-02-05 21:49:25
对于火狐/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('Stop');
} else {
window.frames[0].stop();
}
发布于 2012-06-21 04:08:07
整个代码应该是这样的,(unclenorton的代码行缺少一个括号)
if (typeof (window.frames[0].stop) === 'undefined'){
//Internet Explorer code
setTimeout(function() {window.frames[0].document.execCommand('Stop');},1000);
}else{
//Other browsers
setTimeout(function() {window.frames[0].stop();},1000);
}
发布于 2013-10-10 22:49:43
只是,
document.getElementById("myiframe").src = '';
https://stackoverflow.com/questions/2207501
复制相似问题