如何用js得到當前頁面的url資訊方法

2022-02-25 07:32:40 字數 1361 閱讀 8813

設定或獲取物件指定的檔名或路徑。

alert(window.location.pathname)

設定或獲取整個 url 為字串。

alert(window.location.href);

設定或獲取與 url 關聯的埠號碼。

alert(window.location.port)

設定或獲取 url 的協議部分。

alert(window.location.protocol)

設定或獲取 href 屬性中在井號「#」後面的分段。

alert(window.location.hash)

設定或獲取 location 或 url 的 hostname 和 port 號碼。

alert(window.location.host)

設定或獲取 href 屬性中跟在問號後面的部分。

alert(window.location.search)

獲取變數的值(擷取等號後面的部分)

var url = window.location.search;

//    alert(url.length);

//    alert(url.lastindexof('='));

var loc = url.substring(url.lastindexof('=')+1, url.length);

設定或獲取物件指定的檔名或路徑。

alert(window.location.pathname)

設定或獲取整個 url 為字串。

alert(window.location.href);

設定或獲取與 url 關聯的埠號碼。

alert(window.location.port)

設定或獲取 url 的協議部分。

alert(window.location.protocol)

設定或獲取 href 屬性中在井號「#」後面的分段。

alert(window.location.hash)

設定或獲取 location 或 url 的 hostname 和 port 號碼。

alert(window.location.host)

設定或獲取 href 屬性中跟在問號後面的部分。

alert(window.location.search)

獲取變數的值(擷取等號後面的部分)

var url = window.location.search;

//    alert(url.length);

//    alert(url.lastindexof('='));

var loc = url.substring(url.lastindexof('=')+1, url.length);

js獲取當前頁面的url

設定或獲取物件指定的檔名或路徑。設定或獲取整個 url 為字串。設定或獲取與 url 關聯的埠號碼。設定或獲取 url 的協議部分。設定或獲取 href 屬性中在井號 後面的分段。設定或獲取 location 或 url 的 hostname 和 port 號碼。設定或獲取 href 屬性中跟在問號...

JS獲取當前頁面的URL

var url url window.location.href 獲取完整url alert url url window.location.pathname 獲取檔案路徑 檔案位址 alert url test index.html url window.location.protocol 獲取協...

js獲取當前頁面的url資訊

設定或獲取物件指定的檔名或路徑。alert window.location.pathname 設定或獲取整個 url 為字串。alert window.location.href 設定或獲取與 url 關聯的埠號碼。alert window.location.port 設定或獲取 url 的協議部分...