JQUERY獲取當前頁面的URL信息

做網站需要經常使用jq獲取當前url 所以收集了JQUERY獲取URL的函數的資料

設置或獲取對象指定的文件名或路徑。
window.location.pathname例:http://localhost:8086/topic/index?topicId=361alert(window.location.pathname); 則輸出:/topic/index


設置或獲取整個 URL 為字符串。
window.location.href
例:http://localhost:8086/topic/index?topicId=361alert(window.location.href);
則輸出:http://localhost:8086/topic/index?topicId=361


設置或獲取與 URL 關聯的端口號碼。
window.location.port
例:http://localhost:8086/topic/index?topicId=361alert(window.location.port);
則輸出:8086


設置或獲取 URL 的協議部分。
window.location.protocol
例:http://localhost:8086/topic/index?topicId=361alert(window.location.protocol);
則輸出:http:


設置或獲取 href 屬性中在井號“#”后面的分段。
window.location.hash


設置或獲取 location 或 URL 的 hostname 和 port 號碼。
window.location.host
例:http://localhost:8086/topic/index?topicId=361alert(window.location.host);
則輸出:http:localhost:8086


設置或獲取 href 屬性中跟在問號后面的部分。
window.location.search
例:http://localhost:8086/topic/index?topicId=361alert(window.location.search);
則輸出:?topicId=361


window.location屬性 hash
window.location屬性 描述hash
設置或獲取 href 屬性 中在井號“#”后面的分段。
host 設置或獲取 location 或 URL 的 hostname 和 port 號碼。
hostname 設置或獲取 location 或 URL 的主機名稱部分。
href 設置或獲取整個 URL 為字符串。
pathname 設置或獲取對象指定的文件名或路徑。
port 設置或獲取與 URL 關聯的端口號碼。
protocol 設置或獲取 URL 的協議部分。
search 設置或獲取 href 屬性中跟在問號后面的部分。

附上一個關于PHP中服務器變量獲取query字符串的各個參數方
http://blog.unvs.cn/archives/php-server-url-string.html

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容