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()">
或:
onclick="document.all.ifrmname.document.location.reload()">
方案二:用iframe的id屬性定位
<input type="button" name="Button" value="Button" onclick="ifrmid.window.location.reload()">
終極方案:當iframe的src為其它網站位址(跨域操作時)
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)">
父頁面中存在兩個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("refreshAlarm") 得到的是information.asp頁面中那個iframe标簽,是以對src屬性操作有用。
document.frames("refreshAlarm").document得到iframe裡面的内容,也就是"/public/alarmsum.asp"中的内容。
這裡需要補充說明的是:
采用document.getElementByIdx_x擷取後reload是不可以的
但是可以這樣
var myiframe = document.getElementByIdx_x("iframe1");
myiframe.src = myiframe.src; //這樣同樣可以起到重新整理的效果。
本文轉自許琴 51CTO部落格,原文連結:http://blog.51cto.com/xuqin/1223086,如需轉載請自行聯系原作者