javascript获取当前url网址及其参数方法总结

在WEB开发中,许多开发者都比较喜欢使用javascript来获取当前url网址,本文就此为大家总结一下比较常用获取URL的javascript实现代码,以下示例是前面为相应实现方法,后面是获取URL的效果,下面以例子讲解:

输入的网址是(没有框架):http://localhost:81/Test/1.htm?Did=123
以下为输出:
 

JavaScript代码
  1. //获取Url传过来的值  
  2. function Request(name)  
  3. {  
  4. new RegExp("(^|&)"+name+"=([^&]*)").exec(window.location.search.substr(1));  
  5. return RegExp.$2  
  6. }  
  7.   
  8. thisURL = document.URL; // http://localhost:81/Test/1.htm?Did=123  
  9. thisHREF = document.location.href; // http://localhost:81/Test/1.htm?Did=123  
  10. thisSLoc = self.location.href; // http://localhost:81/Test/1.htm?Did=123  
  11. thisDLoc = document.location; // http://localhost:81/Test/1.htm?Did=123  
  12.   
  13. thisTLoc = top.location.href; // http://localhost:81/Test/1.htm?Did=123  
  14. thisPLoc = parent.document.location;// http://localhost:81/Test/1.htm?Did=123  
  15. thisTHost = top.location.hostname; // localhost  
  16. thisHost = location.hostname; // localhost  
  17.   
  18. thisU1 = window.location.protocol; // http:  
  19. thisU2 = window.location.host; // localhost:81  
  20. thisU3 = window.location.pathname; // /Test/1.htm  

原文:http://www.cnblogs.com/lechie/archive/2010/08/30/2383228.html



评论: 0 | 引用: 0 | 查看次数: 2672
发表评论
昵 称:
密 码: 游客发言不需要密码.
邮 箱: 邮件地址支持Gravatar头像,邮箱地址不会公开.
网 址: 输入网址便于回访.
内 容:
验证码:
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.
字数限制 1000 字 | UBB代码 开启 | [img]标签 关闭

 广告位

↑返回顶部↑