日期:2014-05-16  浏览次数:20383 次

JS实现刷新iframe的方法

JS实现刷新iframe的方法

<!-- 正文开始 -->

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

方案一:用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()">

  方案二:用iframe的id属性定位

<input type="button" name="Button" value="Button"
onclick="ifrmid.window.location.reload()">

  终极方案:当iframe的src为其它网站地址(跨域操作时)

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

?

?

?

代码如下:<input type=button value=刷新 onclick="history.go(0)">

代码如下:<input type=button value=刷新 onclick="location.reload()">

代码如下:<input type=button value=刷新 onclick="location=location">

代码如下:<input type=button value=刷新 onclick="window.navigate(location)">

代码如下:<input type=button value=刷新 onclick="location.replace(location)">

下面这三种我就不知道该怎么用了,就把代码放在下面吧,哪位要是会的话,可教教大家。

<input type=button value=刷新 onclick="document.execCommand(@#Refresh@#)">

<input type=button value=刷新 onclick="window.open(@#自身的文件@#,@#_self@#)">

<input type=button value=刷新 onClick=document.all.WebBrowser.ExecWB(22,1)>

?

?

?


父页面中存在两个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); //ok

document.frames("refreshAlarm").document.location.reload(true); //ok

document.frames("refreshAlarm").document.location="/public/alarmsum.asp";//ok

document.getElementByIdx_x("refreshAlarm").src="/public/alarmsum.asp" mce_src="/public/alarmsum.asp"; //ok

document.frames("refreshAlarm").src="/public/alarmsum.asp" mce_src="/public/alarmsum.asp"; //没变化,没动静

注意区别,document.all.refreshAlarm 或 document.frames("