---恢復(fù)內(nèi)容開始---
1.location.href.....
(1)self.loction.href="       window.location.href="(2)this.location.href="(3) parent.location.href="(4) top.location.href=" 2. 關(guān)于刷新頁面  (1)window.location.href=http://www.cnblogs.com/nana-share/p/window.location.href 3.  (1)第一段為實(shí)際在用的   例如像獲取下面鏈接的郵箱   http://agent/index.php/Home/Login/getpwd_check_email?code=824790&to=1321136493@qq.com var mail = getURLParameter('to'); ---恢復(fù)內(nèi)容結(jié)束--- 下面再來看一下js操作url的代碼 代碼很簡(jiǎn)單,主要一個(gè)思路是把url參數(shù)解析為js對(duì)象,再做增、刪、改、查操作就很方便了~,這里做筆記。 LG只是我個(gè)人共同JS的名稱空間,無他。調(diào)用:
 (2)window.location.Reload()
    都是刷新當(dāng)前頁面。區(qū)別在于是否有提交數(shù)據(jù)。當(dāng)有提交數(shù)據(jù)時(shí),window.location.Reload()會(huì)提示是否提交,window.location.href=http://www.cnblogs.com/nana-share/p/window.location.href;則是向指定的url提交數(shù)據(jù)function getURLParameter(name) {2 3       return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search) || [, ""])[1].replace(//+/g, '%20')) || null; //構(gòu)造一個(gè)含有目標(biāo)參數(shù)的正則表達(dá)式對(duì)象4 5   }//獲取url中的參數(shù)2     function getUrlParam(name){3      var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //構(gòu)造一個(gè)含有目標(biāo)參數(shù)的正則表達(dá)式對(duì)象4      var r = window.location.search.substr(1).match(reg); //匹配目標(biāo)參數(shù)5      if (r != null) return unescape(r[2]); return null; //返回參數(shù)值6    }var LG=(function(lg){  var objURL=function(url){    this.ourl=url||window.location.href;    this.href="";//?前面部分    this.params={};//url參數(shù)對(duì)象    this.jing="";//#及后面部分    this.init();  }  //分析url,得到?前面存入this.href,參數(shù)解析為this.params對(duì)象,#號(hào)及后面存入this.jing  objURL.prototype.init=function(){    var str=this.ourl;    var index=str.indexOf("#");    if(index>0){      this.jing=str.substr(index);      str=str.substring(0,index);    }    index=str.indexOf("?");    if(index>0){      this.href=str.substring(0,index);      str=str.substr(index+1);      var parts=str.split("&");      for(var i=0;i<parts.length;i++){        var kv=parts[i].split("=");        this.params[kv[0]]=kv[1];      }    }    else{      this.href=this.ourl;      this.params={};    }  }  //只是修改this.params  objURL.prototype.set=function(key,val){    this.params[key]=val;  }  //只是設(shè)置this.params  objURL.prototype.remove=function(key){    this.params[key]=undefined;  }  //根據(jù)三部分組成操作后的url  objURL.prototype.url=function(){    var strurl=this.href;    var objps=[];//這里用數(shù)組組織,再做join操作    for(var k in this.params){      if(this.params[k]){        objps.push(k+"="+this.params[k]);      }    }    if(objps.length>0){      strurl+="?"+objps.join("&");    }    if(this.jing.length>0){      strurl+=this.jing;    }    return strurl;  }  //得到參數(shù)值  objURL.prototype.get=function(key){    return this.params[key];  }    lg.URL=objURL;  return lg;}(LG||{}));var myurl=new LG.URL("http://www.baidu.com?a=1");  myurl.set("b","hello"); //添加了b=hello  alert (myurl.url());  myurl.remove("b"); //刪除了b  alert(myurl.get ("a"));//取參數(shù)a的值,這里得到1  myurl.set("a",23); //修改a的值為23  alert (myurl.url());
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注