window.parent與window.openner區別介紹

來源:互聯網
上載者:User

標籤:

轉自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區別介紹

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.