JS獲取當前網址信息

經過window.location對象獲取對應的屬性html

一、設置或獲取對象指定的文件名或路徑(pathname)前端

 

window.location.pathnamegit

二、設置或獲取整個 URL 爲字符串(href)github

 

window.location.href正則表達式

三、設置或獲取與 URL 關聯的端口號碼(port)小程序

 

window.location.port微信小程序

四、設置或獲取 URL 的協議部分(protocol)微信

window.location.protocoldom

設置或獲取 href 屬性中在井號「#」後面的分段(hash)url

window.location.hash

設置或獲取 location 或 URL 的 hostname 和 port 號碼(host)

window.location.host

 

設置或獲取 href 屬性中跟在問號後面的部分(search)

window.location.search

獲取變量的值(截取等號後面的部分)

window.location.search.substring(url.lastIndexOf('=')+1, url.length);

用來獲得當前網頁的域名

document.domain

注意:

一、獲取事後直接使用substring方法截取咱們須要的信息。

二、經過正則表達式準確的獲取咱們須要的參數。

其餘

[個人博客,歡迎交流!](http://rattenking.gitee.io/stone/index.html)

[個人CSDN博客,歡迎交流!](https://blog.csdn.net/m0_38082783)

[微信小程序專欄](https://blog.csdn.net/column/details/18335.html)

[前端筆記專欄](https://blog.csdn.net/column/details/18321.html)

[微信小程序實現部分高德地圖功能的DEMO下載](http://download.csdn.net/download/m0_38082783/10244082)

[微信小程序實現MUI的部分效果的DEMO下載](http://download.csdn.net/download/m0_38082783/10196944)

[微信小程序實現MUI的GIT項目地址](https://github.com/Rattenking/WXTUI-DEMO)

[微信小程序實例列表](http://blog.csdn.net/m0_38082783/article/details/78853722)

[前端筆記列表](http://blog.csdn.net/m0_38082783/article/details/79208205)

[遊戲列表](http://blog.csdn.net/m0_38082783/article/details/79035621)

相關文章
相關標籤/搜索