如何用js得到當前頁面的url信息方法(JS獲取當前網址信息)


1,設置或獲取對象指定的文件名或路徑。

alert(window.location.pathname)

2,設置或獲取整個 URL 為字符串。

alert(window.location.href);

3,設置或獲取與 URL 關聯的端口號碼。

alert(window.location.port)

4,設置或獲取 URL 的協議部分。

alert(window.location.protocol)

5,設置或獲取 href 屬性中在井號“#”后面的分段。

alert(window.location.hash)

6,設置或獲取 location 或 URL 的 hostname 和 port 號碼。

alert(window.location.host)

7,設置或獲取 href 屬性中跟在問號后面的部分。

alert(window.location.search)

8,獲取變量的值(截取等號后面的部分)

 var url = window.location.search;

//    alert(url.length);

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

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

9,用來得到當前網頁的域名

var domain = document.domain;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM