码迷,mamicode.com
首页 > Web开发 > 详细

js对URL的相关操作集锦

时间:2015-10-28 16:58:19      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:

---恢复内容开始---

1.location.href.....

(1)self.loction.href="/url"

       window.location.href="/url"    以上两个用法相同均为在当前页面打开URL页面

(2)this.location.href="/url"    当前页面打开URL

(3) parent.location.href="/url"   在父页面打开新页面,如果页面中自定义了frame,那么可将parent self top换为自定义frame的名称,效果是在frame窗口打开url地址

(4) top.location.href="/url"   在顶层页面打开新页面

2. 关于刷新页面

 (1)window.location.href=window.location.href

 (2)window.location.Reload()

    都是刷新当前页面。区别在于是否有提交数据。当有提交数据时,window.location.Reload()会提示是否提交,window.location.href=window.location.href;则是向指定的url提交数据

3.

 (1)第一段为实际在用的

1  function getURLParameter(name) {
2 
3      return decodeURIComponent((new RegExp(‘[?|&]‘ + name + ‘=‘ + ‘([^&;]+?)(&|#|;|$)‘).exec(location.search) || [, ""])[1].replace(/\+/g, ‘%20‘)) || null; //构造一个含有目标参数的正则表达式对象
4 
5   }

1  //获取url中的参数
2         function getUrlParam(name) {
3             var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
4             var r = window.location.search.substr(1).match(reg);  //匹配目标参数
5             if (r != null) return unescape(r[2]); return null; //返回参数值
6         }

  例如像获取下面链接的邮箱

  http://agent/index.php/Home/Login/getpwd_check_email?code=824790&to=1321136493@qq.com

   

var mail = getURLParameter(‘to‘);

 

---恢复内容结束---

js对URL的相关操作集锦

标签:

原文地址:http://www.cnblogs.com/nana-share/p/4917656.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!