js獲取當前地址信息



var url = window.location.href;  //獲取當前窗口的Url;  結果:http://localhost:61768/Home/Index?id=2&age=18
var host = window.location.host; //獲取當前窗口的主機名;   結果:localhost:61768
var port = window.location.port;  //獲取當前窗口的端口; 結果:61768
var pathname = window.location.pathname; //獲取當前窗口的路徑 ; 結果:/Home/Index
var URL = document.URL;          //獲取當前文檔的Url;結果:http://localhost:61768/Home/Index?id=2&age=18
var search = window.location.search;   //獲取參數;結果:?id=2&age=18

var protocol =  window.location.protocol;   //獲的是當前地址的協議    結果:http:
  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM