標籤:
轉自http://www.jb51.net/article/30086.htm
首先來說說 parent.window與top.window的用法
"window.location.href"、"location.href"是本頁面跳轉
"parent.location.href"是上一層頁面跳轉
"top.location.href"是最外層的頁面跳轉
舉例說明:
如果A,B,C,D都是jsp,D是C的iframe,C是B的iframe,B是A的iframe,如果D中js這樣寫
"window.location.href"、"location.href":D頁面跳轉
"parent.location.href":C頁面跳轉
"top.location.href":A頁面跳轉
現在終於明白了串連的時候target的用法了:
_blank:重新開啟一個視窗
_parent:父視窗執行重新導向
_self:自身頁面重新導向
_top:第一個父視窗重新導向
綜上所述可知:parent.window:父視窗對象 top.window:第一個父視窗的對象
下面來重點看看window.parent與window.openner區別
window.parent 是iframe頁面調用父頁面對象,當我們想從iframe內嵌的頁面中訪問外層頁面是可以直接利用window.parent擷取;
下面來舉幾個常用的例子:
parent.window與top.window一般在分割的頁面即 frameset或iframe中使用
登出整個架構後返回到login.aspx:parent.window.location=‘Login.aspx‘或者
top.window.location=‘Login.aspx‘
window.parent也是常在架構中使用,
重新整理:window.parent.location.reload();或者重新整理某個架構:window.parent.MainForm.location.reload();
獲得其他架構的元素值:window.parent.MainForm.form1.text1.value;
window.opener主要是獲得通過超連結或者 window.open() 開啟本身頁面的頁面的一些,比如獲得值,重新整理等
重新整理:window.opener.location.reload();
獲值:window.opener.document.getElement("txtName").value;
後退:top.playFrame.history.go(-1);
前進: top.playFrame.history.go(1);
重新整理: top.playFrame.location.reload();
就總結到這裡,這些對象很實用
window.parent與window.openner區別介紹