javascript中的location.href有很多種用法,主要如下。
self.location.href="/url" 當前頁面打開URL頁面location.href="/url" 當前頁面打開URL頁面windows.location.href="/url" 當前頁面打開URL頁面,前面三個用法相同。this.location.href="/url" 當前頁面打開URL頁面parent.location.href="/url" 在父頁面打開新頁面top.location.href="/url" 在頂層頁面打開新頁面
如果頁面中自定義了frame,那么可將parent self top換為自定義frame的名稱,效果是在frame窗口打開url地址
此外,window.location.href=window.location.href;和window.location.Reload()和都是刷新當前頁面。區別在于是否有提交數據。當有提交數據時,window.location.Reload()會提示是否提交,window.location.href=window.location.href;則是向指定的url提交數據..
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頁面刷新
新聞熱點
疑難解答