js的location.href的幾種用法


        工作中頁面刷新的幾種方法,查閱資料(bd)后如下:

        Javascript中的location.href有很多種用法,主要如下:

   self.location.href="/url" 當前頁面打開URL頁面
   ocation.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頁面刷新

        Javascript刷新頁面的幾種方法:
        1 history.go(0) 
        2 location.reload() 
        3 location=location 
        4 location.assign(location) 
        5 document.execCommand('Refresh') 
        6 window.navigate(location) 
        7 location.replace(location) 
        8 document.URL=location.href


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM