js獲取當前URL、參數、端口、IP等服務器信息




1,設置或獲取對象指定的文件名或路徑。
console.log(window.location.pathname)

2,設置或獲取整個 URL 為字符串。
console.log(window.location.href);

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

console.log(window.location.port)


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

console.log(window.location.protocol)


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

console.log(window.location.hash)

 

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

console.log(window.location.host)

    1

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

console.log(window.location.search)



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

 var url = window.location.search;

  

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

var domain = document.domain;

 

function getRootPath() {
    //獲取當前網址,
    var curPath = window.document.location.href;
    //獲取主機地址之后的目錄,
    var pathName = window.document.location.pathname;
    var pos = curPath.indexOf(pathName);
    //獲取主機地址
    var localhostPaht = curPath.substring(0, pos);
    //獲取帶"/"的項目名,
    var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
    return (localhostPaht);
}


免責聲明!

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



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