獲取當前url js
- IT科技
- 關注:1.74W次
url一般指統一資源定位系統,即uniform resource locator,是因特網的全球資訊網服務程式上用於指定資訊位置的表示方法。
假設當前頁完整地址是:http://localhost:61768/Home/Index?id=2&age=18
1、獲取當前視窗的Url
var url = window.location.href;
//結果:http://localhost:61768/Home/Index?id=2&age=18
2、獲取當前視窗的主機名
var host = window.location.host;
//結果:localhost:61768
3、獲取當前視窗的埠
var port = window.location.port;
//結果:61768
4、獲取當前視窗的路徑
var pathname = window.location.pathname;
//結果:/Home/Index
5、獲取當前文件的Url
var URL = document.URL;
//結果:http://localhost:61768/Home/Index?id=2&age=18
6、獲取引數
var search = window.location.search;
//結果:?id=2&age=18
關於js 獲取當前url的方法,我們就瞭解到這啦!
- 文章版權屬於文章作者所有,轉載請註明 https://shqsg.com/dianzi/morrr3.html