1.獲取父頁面的一個span的內(nèi)容
var username=$("#user",parent.document).text();
2.如果需要獲取的元素和當(dāng)前iframe還隔著好幾個iframe可以用
var username=$("#user",top.document).text();
可以看出來parent
是獲取上一層窗體的內(nèi)容 而top
是獲取頂層窗口的內(nèi)容
下邊摘抄自網(wǎng)頁
"window.location.href"、"location.href"是本頁面跳轉(zhuǎn)
"parent.location.href"是上一層頁面跳轉(zhuǎn)
"top.location.href"是最外層的頁面跳轉(zhuǎn)
舉例說明:
如果A,B,C,D都是jsp傀蓉,D是C的iframe,C是B的iframe,B是A的iframe幕袱,如果D中js這樣寫
"window.location.href"台谢、"location.href":D頁面跳轉(zhuǎn)
"parent.location.href":C頁面跳轉(zhuǎn)
"top.location.href":A頁面跳轉(zhuǎn)
現(xiàn)在終于明白了連接的時候target的用法了:
_blank:重新打開一個窗口
_parent:父窗口執(zhí)行重定向
_self:自身頁面重定向
_top:第一個父窗口重定向
綜上所述可知:parent.window:父窗口對象 top.window:第一個父窗口的對象
下面來重點看看window.parent與window.openner區(qū)別
window.parent 是iframe頁面調(diào)用父頁面對象搁骑,當(dāng)我們想從iframe內(nèi)嵌的頁面中訪問外層頁面是可以直接利用window.parent獲取矾缓;