首先我們了解:window.location.href、location.href、self.location.href、parent.location.href、top.location.href他們的區別與聯繫,簡單的說:幾種location.href的區別js實作網頁被iframe框架功能
"window.location.href"、"location.href"、"self.location.href"是本頁跳轉
"parent.location.href"是上一層頁跳到
"top.location.href"是最外層的頁面跳轉
舉個例子說明(如上圖):
如果A,B,C,D都是普通頁面,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頁跳轉
如果D頁有form的話: