javaScript獲取當前Url的方法

1.(獲取全部的url)
    方法1:var thisURL = document.URL;     //   http://localhost:81/admin/welcome.htm?Did=123
    方法2:var thisHref = document.location.href; //   http://localhost:81/admin/welcome.htm?Did=123
    方法3:var thisURL = self.location.href;   //   http://localhost:81/admin/welcome.htm?Did=123
    方法4:var thisURL = document.location;  //   http://localhost:81/admin/welcome.htm?Did=123
  

2.(適用於frame框架下獲取鏈接)
    方法1:var thisTLoc = top.location.href;   //   http://localhost:81/admin/index.html
    方法2:thisPLoc = parent.document.location;  //   http://localhost:81/admin/index.html
 
3. 
(獲取網址)
    方法1:var thisTHost = top.location.hostname; //   localhost
    方法2:var Url= location.hostname;  //   localhost

4.(獲取url中不同部分)
    thisU1 = window.location.protocol; //    http:
    thisU2 = window.location.host;   //   localhost:81

    thisU3 = window.location.pathname; //      /admin/index.html
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章