天天看點

JS擷取目前頁碼URL中資訊

一、設定或擷取對象指定的檔案名或路徑:

window.location.pathname

二、設定或擷取整個 URL 為字元串:

window.location.href

三、設定或擷取與 URL 關聯的端口号碼:

window.location.port

四、設定或擷取 URL 的協定部分。

window.location.protocol

五、設定或擷取 href 屬性中在井号“#”後面的分段:

window.location.hash

六、設定或擷取 location 或 URL 的 hostname 和 port 号碼:

window.location.host

七、設定或擷取 href 屬性中跟在問号後面的部分。

window.location.search

八、擷取變量的值(截取等号後面的部分)

    var url = window.location.search;

//    alert(url.length);

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

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

繼續閱讀