JavaScript Window Location

來源:互聯網
上載者:User

標籤:col   htm   toc   func   w3c   nbsp   路徑名   ref   UNC   

1.JavaScript Window Location

window.location 對象用於獲得當前頁面的地址 (URL),並把瀏覽器重新導向到新的頁面。

1.1Window Location

window.location 對象在編寫時可不使用 window 這個首碼。 一些例子:

一些執行個體:

  • location.hostname 返回 web 主機的網域名稱
  • location.pathname 返回當前頁面的路徑和檔案名稱
  • location.port 返回 web 主機的連接埠 (80 或 443)
  • location.protocol 返回所使用的 web 協議(http:// 或 https://)

1.2Window Location Href

location.href 屬性返回當前頁面的 URL。

返回(當前頁面的)整個 URL:

<script>document.write(location.href);</script>

1.3Window Location Pathname

location.pathname 屬性返回 URL 的路徑名。

<script>document.write(location.pathname);</script>

1.4Window Location Assign

location.assign() 方法載入新的文檔。

<html><head><script>function newDoc()  {  window.location.assign("http://www.w3cschool.cc")  }</script></head><body><input type="button" value="Load new document" onclick="newDoc()"></body></html>

2.JavaScript Window History

window.history 對象包含瀏覽器的曆史。

2.1Window History

window.history對象在編寫時可不使用 window 這個首碼。

為了保護使用者隱私,對 JavaScript 訪問該對象的方法做出了限制。

一些方法:

  • history.back() - 與在瀏覽器點擊後退按鈕相同
  • history.forward() - 與在瀏覽器中點擊向前按鈕相同

2.2Window History Back

history.back() 方法載入曆史列表中的前一個 URL。

這與在瀏覽器中點擊後退按鈕是相同的:

<html><head><script>function goBack()  {  window.history.back()  }</script></head><body><input type="button" value="Back" onclick="goBack()"></body></html>

 

JavaScript Window Location

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.