用js獲取當前頁面的url

2022-02-01 04:51:54 字數 345 閱讀 6181

1.獲取當前或者指定頁面的檔名或路徑 window.location.pathname

2.設定或獲取整個url字串 window.location.href

3.設定或獲取url相關的埠號 window.location.port

4.設定或獲取url的協議部分 window.location.protocol

5.獲取href中"#"後面的部分 window.location.hash

6.設定或者獲取url的hostname或者port window.location.host

7.設定或者獲取href屬性中問號"?"後面的部分 window.location.search

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 獲取協...

獲取當前頁面的URL

window location host 返回url 的主機部分,例如 www.com window location hostname 返回www.com window location href 返回整個url字串 window location pathname 返回 a index.php或...