javascript实现刷新iframe的方法的总结,现在假设存在下面这样一个iframe,则刷新该iframe的N种方法有:
复制代码
<iframe src="1.htm" name="ifrmname" id="ifrmid"></iframe>
第一种方法:用iframe的name属性定位
复制代码
<input type="button" name="Button" value="Button" οnclick="document.frames('ifrmname').location.reload()">
或者
复制代码
<input type="button" name="Button" value="Button" οnclick="document.all.ifrmname.document.location.reload()">
第二种方法:用iframe的id属性定位
复制代码
<input type="button" name="Button" value="Button" οnclick="ifrmid.window.location.reload()">
第三种方法:当iframe的src为其它网站地址(即跨域操作时)
复制代码
<input type="button" name="Button" value="Button" οnclick="window.open(document.all.ifrmname.src,'ifrmname','')">
父页面中存在两个iframe,一个iframe中是一个链接列表,其中的链接指向另一个iframe,用于显示内容。现在当内容内容添加后,在链接列表中添加了一条记录,则需要刷新列表iframe。
在内容iframe的提交js中使用parent.location.reload()将父页面全部刷新,因为另一个iframe没有默认的url,只能通过列表选择,所以只显示了列表iframe的内容。
使用window.parent.frames["列表iframe名字"].location="列表url"即可进刷新列表iframe,而内容iframe在提交后自己的刷新将不受影响。
复制代码
document.frames("refreshAlarm").location.reload(true);
document.frames("refreshAlarm").document.location.reload(true);
document.frames("refreshAlarm").document.location="
http://www.jb51.net/";
document.frames("refreshAlarm").src="
http://www.jb51.net/";
注意区别:document.all.refreshAlarm 或 document.frames("refreshAlarm") 得到的是http://www.jb51.net/页面中那个iframe标签,所以对src属性操作有用。
document.frames("refreshAlarm").document得到iframe里面的内容,也就是"http://www.jb51.net/"中的内容。
reload 方法,该方法强迫浏览器刷新当前页面。
语法:location.reload([bForceGet])
参数: bForceGet, 可选参数, 默认为 false,从客户端缓存里取当前页。true, 则以 GET 方式,从服务端取最新的页面, 相当于客户端点击 F5("刷新")
代码如下 | |
|
这样就实现了页面刷新了,当然还有其它办法了,那么要刷新框架页面我们要如何操作
代码如下 | |
|
实例:
代码如下 | |
|
二。jQuery实现强制刷新
$('#iframe').attr('src', $('#iframe').attr('src'));
三,如果是打开的新页面我们要刷新的话可以使用如下代码来刷亲
代码如下 | |
|
javascript(js)自动刷新页面的实现方法总结:
间隔10秒刷新一次,在页面的head标签中加入下面的代码段:
复制代码
<meta http-equiv="refresh"content="10;url=跳转的页面或者是需要刷新的页面URL地址">
定时刷新页面(间隔2秒刷新一下页面):
复制代码
<script language="javascript">
setTimeout("location.href='url'",2000);//url是要刷新的页面URL地址
</script>
直接刷新页面事件:
复制代码
<script language="javascript">
window.location.reload(true);
//如需刷新iframe,则只需把window替换为响应的iframe的name属性值或ID属性值
</script>
直接刷新页面事件:
复制代码
<script language=''javascript''>
window.navigate("本页面url");
</script>
直接刷新页面事件:
复制代码
function abc(){
window.location.href="/blog/window.location.href";
setTimeout("abc()",10000);
}
刷新框架页:
复制代码
<script language="javascript">
top.leftFrm.location.reload();
parent.frmTop.location.reload();
</script>