query= window.location.search.substring(1); urlParams={};while(match =search.exec(query)) urlParams[decode(match[1])] = decode(match[2]); })(); //urlParams的结果urlParams={ param:"yes", article:"1"} console.log(urlParams["param"]);//-> "yes"console.log("article"inurlParams);...
query= window.location.search.substring(1); urlParams={};while(match =search.exec(query)) urlParams[decode(match[1])] = decode(match[2]); })(); //urlParams的结果urlParams={ param:"yes", article:"1"} console.log(urlParams["param"]);//-> "yes"console.log("article"inurlParams);...
function urlToObj(url){ var match, pl = /\+/g, search = /([^&=]+)=?([^&]*)/g, decode = function(s) { return decodeURIComponent(s.replace(pl, " ")); }, query = url ? (url.split('?'))[1] : window.location.search.substring(1); urlParams = {}; while (match = se...
if(myurl !=null && myurl.toString().length>1) { alert(GetQueryString("url")); } 1. 2. 3. 4. 5. 这样就不会报错了! 方法二:传统方法 function UrlSearch() { var name,value; var str=location.href; //取得整个地址栏 var num=str.indexOf("?") str=str.substr(num+1); //取得所...
); console.log(url.searchParams.get('query'); // foobar console.log(url.searchParams.get('...
下面通过一段代码给大家介绍js中获取URL参数的共用方法getRequest()方法,具体代码如下所示: getRequest : function() { var url = location.search; //获取url中"?"符后的字串 var theRequest = new Object(); if (url.indexOf("?") != -1) { var str = url.substr(1); strs = str.split("&...
javascript获取URL查询字符串 function getArgs( ) { var args = new Object( ); var query = location.search.substring(1); // Get query string var pairs = query.split("&"); // Break at ampersand for(var i = 0; i < pairs.length; i++) {...
//lastest: url paramter: //测试链接:test getQueryString var queryStrings=function() {//get url querystring var params=document.location.search,reg=/(?:^\?|&)(.*?)=(.*?)(?=&|$)/g,temp,args={}; while((temp=reg.exec(params))!=null) args[temp[1]]=decode...
'?')[1]; const params = new URLSearchParams(paramsString); const paramValue = params.get('...
function getUrlParams() { var params = {}; window.location.search.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(str,key,value) { params[key] = value; }); return params; } In the above code, “window.location.search” is to get the query string, “replace” function and re...