1. 程式人生 > >js頁面跳轉的問題(跳轉到父頁面、最外層頁面、本頁面)

js頁面跳轉的問題(跳轉到父頁面、最外層頁面、本頁面)

"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頁面跳轉 

如果D頁面中有form的話,

<form>: form提交後D頁面跳轉 


<form target="_blank">: form提交後彈出新頁面 

<form target="_parent">: form提交後C頁面跳轉 

<form target="_top"> : form提交後A頁面跳轉 

關於頁面重新整理,D 頁面中這樣寫:

"parent.location.reload();": C頁面重新整理 (當然,也可以使用子視窗的 opener 物件來獲得父視窗的物件:window.opener.document.location.reload(); ) 

"top.location.reload();": A頁面重新整理