通過JavaScript的location對象,可獲取URL中的協議、主機名、端口、錨點、查詢參數等信息。
示例
URL:http://www.akmsg.com/WebDemo/URLParsing.html#top?username=admin&pwd=123456
解析結果:
代碼
console.log( 'location.hash :' + location.hash + '\r\n' + 'location.host :' + location.host + '\r\n' + 'location.hostname :' + location.hostname + '\r\n' + 'location.href :' + location.href + '\r\n' + 'location.pathname :' + location.pathname + '\r\n' + 'location.port :' + location.port + '\r\n' + 'location.protocol :' + location.protocol + '\r\n' + 'location.hash :' + location.hash + '\r\n' + 'location.search :' + location.search + '\r\n' + 'location.origin :' + location.origin )
在線示例
地址:http://www.akmsg.com/WebDemo/URLParsing.html
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com