(window.location 獲取url各項參數(shù)詳解)[https://blog.jimliu.xyz/2017/02/16/window-location/]
近期在寫一些廣告投放頁時舒帮,遇到了一點小問題。在此記錄一下:
現(xiàn)在有這樣一個 URL
http://blog.jimliu.xyz:80/window.location.html?ver=1.0&id=6#imhere
1. window.location.href 地址欄所有內(nèi)容
http://blog.jimliu.xyz:80/aaa/window.location.html?ver=1.0&id=6#imhere
2. window.location.protocol URL 的協(xié)議部分
http:
3. window.location.host URL的主機的部分
blog.jimliu.xyz
4. window.location.port URL中的端口號
(如果采用默認的80端口(update:即使添加了:80),那么返回值并不是默認的80而是空字符
本例返回值:")
""
5. window.location.pathname URL 的路徑部分(就是文件地址)
/aaa/window.location.html
6. window.location.search 查詢(參數(shù))部分
?ver=1.0&id=6
7. window.location.hash 獲取錨點
#imhere