js獲取當前URL 引數 埠 IP等資訊

2021-09-20 01:14:22 字數 785 閱讀 9871

以下列出均為常用(**位址為:

1、設定或獲取整個 url 為字串

window.location.href

2、設定或獲取 url 的協議部分

window.location.protocol

3、設定或獲取 url 的主機部分

window.location.host

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

window.location.port

5、設定或獲取與 url 的路徑部分(就是檔案位址)

window.location.pathname

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

window.location.search

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

window.location.hash

js獲取當前URL 引數 埠 IP等資訊

因之前vue專案裡面使用到裡面的部分功能,因此對該部分內容做了歸納整理,可能不是很全 1 設定或獲取整個 url 為字串 window.location.href 2 設定或獲取 url 的協議部分 window.location.protocol 3 設定或獲取 url 的主機部分 window....

js獲取當前URL 引數 埠 IP等資訊

以下列出均為常用 位址為 1 設定或獲取整個 url 為字串 window.location.href 2 設定或獲取 url 的協議部分 window.location.protocol 3 設定或獲取 url 的主機部分 window.location.host 4 設定或獲取與 url 關聯的...

js獲取當前URL 引數 埠 IP等伺服器資訊

1,設定或獲取物件指定的檔名或路徑。console.log window.location.pathname 2,設定或獲取整個 url 為字串。console.log window.location.href 3,設定或獲取與 url 關聯的埠號碼。console.log window.locat...