`
soli
  • 浏览: 10727 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

JS实现刷新iframe的方法

    博客分类:
  • Web
阅读更多
对于如下一个 iframe,用 js 有什么么方法可以刷新它呢:

<iframe src="1.htm" name="ifrmname" id="ifrmid"></iframe>


方法一、location.reload()

根据定位 iframe 的方式不同,有以下方法:

1. 用iframe的name属性定位

<input type="button" name="Button" value="Button" 
onclick="document.frames('ifrmname').location.reload()">




<input type="button" name="Button" value="Button" 
onclick="document.all.ifrmname.document.location.reload()">


2. 用iframe的id属性定位
<input type="button" name="Button" value="Button" 
onclick="ifrmid.window.location.reload()">


方法二、window.open()

<input type="button" name="Button" value="Button" 
onclick="window.open(document.all.ifrmname.src,'ifrmname','')">


该方法尤其适用于 iframe 的 src 为其它网站地址,即跨域操作的情况。

方法三、给 src 属性重新赋值

<input type="button" name="Button" value="Button" 
onclick="ifrmid.src=ifrmid.src">


方法四、给 href 属性重新赋值

<input type="button" name="Button" value="Button" 
onclick="ifrmid.location.href=ifrmid.src">


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics