javascript深入之location對象和history對象

來源:互聯網
上載者:User
瀏覽器的location 和history對象:一、location對象:1>location.reload() 相當於按瀏覽器上的“重新整理”(IE)或“Reload”(Netscape)鍵。 從web伺服器上再次裝入當前顯示的頁面。2>location.replace(url) 開啟一個 URL,並替換瀏覽器曆史列表中當前位置的地址。用這個方法開啟一個 URL 後,按下瀏覽器的“後退”鍵將不能返回到剛才的頁面。 demo:<body ><span id="myspan">fdasfdasdfasfdasfda</span><script>var s=document.getElementById("myspan");s.onclick=function(){location.reload("http://www.baidu.com");};</script></body>使用reload方法時,後退按鈕可以點擊,而使用replace()方法時,後退按鈕為灰色,不可點擊;a)解析URL的參數,產生json對象。var getURLParamsObj=function(url){    var n=url.indexOf("?"),parse = url.substring(n+1),arr = parse.split("&"),obj={};for(var i=0,len=arr.length; i<len; i++){var a = arr[i],name,value,pos = a.indexOf("=");if(pos == -1){continue;}name = a.substring(0,pos);value = a.substring(pos+1);obj[name]= decodeURIComponent(value);}return obj;}b)window.location與document.location的不同:1>window.location是一個對象,而document.location只是一個字串和document.url同義。2>大多數情況下,document.location和location.href是相同的,但是當存在伺服器重新導向時,document.location表示的是已裝載的URL,而location.href是原始請求文檔的URL二、history對象:window.history 即history是window對象的一個屬性a)支援三種方法:back(),forward(),go();b)基於Mozilla瀏覽器也支援window.back()和window.forward(),和後退,前進兩個按鈕功能相同,但是當使用幀的時候,window.back()和history.back()執行的操作不同。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.