您的位置:首页 > Web前端 > JavaScript

javaScript获取当前Url的方法

2016-02-17 09:58 711 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: