js/jquery中刷新iframe方法(兼容主流)

日期 2014年04月17日 16:56

分类 Web

标签 jquery

浏览 45410

字数统计: 678(字)

本文发布于 10 年前, 内容可能已经过时或失效!

文章目录

一 js原生实现iframe刷新两种方式:

//方法1
document.getElementById('FrameID').contentWindow.location.reload(true);
//方法2
document.getElementById('youriframe').src=src;

实例:

<iframe id="myframe" width="100%" frameBorder="0" src="test.html" scrolling="no"></iframe>
<input type="button" onclick="javascript:refreshFrame();" value="Refresh Frame" />
 
<script type="text/javascript">
function refreshFrame(){
    document.getElementById('myframe').contentWindow.location.reload(true);
}
</script>

二 jquery实现强制刷新iframe

$('#iframe').attr('src', $('#iframe').attr('src'));

总结:网上一大堆document.frames('ifrmname').location.reload()已经不能用了