Skip to main content
added 319 characters in body
Source Link
AwokeKnowing
  • 8.3k
  • 9
  • 40
  • 49

I always stick this as one line. Now params has the vars:

params={};location.search.replace(/[?&]+([^=&]+)=([^&]*)/gi,function(s,k,v){params[k]=v}) 

multi-lined:

var params={}; window.location.search .replace(/[?&]+([^=&]+)=([^&]*)/gi, function(str,key,value) { params[key] = value; } ); 

as a function

function getSearchParams(k){ var p={}; location.search.replace(/[?&]+([^=&]+)=([^&]*)/gi,function(s,k,v){p[k]=v}) return k?p[k]:p; } 

which you could use as:

getSearchParams() //returns {key1:val1, key2:val2} 

or

getSearchParams("key1") //returns val1 

I always stick this as one line. Now params has the vars:

params={};location.search.replace(/[?&]+([^=&]+)=([^&]*)/gi,function(s,k,v){params[k]=v}) 

multi-lined:

var params={}; window.location.search .replace(/[?&]+([^=&]+)=([^&]*)/gi, function(str,key,value) { params[key] = value; } ); 

I always stick this as one line. Now params has the vars:

params={};location.search.replace(/[?&]+([^=&]+)=([^&]*)/gi,function(s,k,v){params[k]=v}) 

multi-lined:

var params={}; window.location.search .replace(/[?&]+([^=&]+)=([^&]*)/gi, function(str,key,value) { params[key] = value; } ); 

as a function

function getSearchParams(k){ var p={}; location.search.replace(/[?&]+([^=&]+)=([^&]*)/gi,function(s,k,v){p[k]=v}) return k?p[k]:p; } 

which you could use as:

getSearchParams() //returns {key1:val1, key2:val2} 

or

getSearchParams("key1") //returns val1 
deleted 2 characters in body
Source Link
AwokeKnowing
  • 8.3k
  • 9
  • 40
  • 49

I always stick this as one line. Now params has the vars:

params={};location.search.replace(/[?&]+([^=&]+)=([^&]*)/gi,function(s,k,v){params[k]=v;params[k]=v}); 

multi-lined:

var params={}; window.location.search .replace(/[?&]+([^=&]+)=([^&]*)/gi, function(str,key,value) { params[key] = value; } ); 

I always stick this as one line. Now params has the vars:

params={};location.search.replace(/[?&]+([^=&]+)=([^&]*)/gi,function(s,k,v){params[k]=v;}); 

multi-lined:

var params={}; window.location.search .replace(/[?&]+([^=&]+)=([^&]*)/gi, function(str,key,value) { params[key] = value; } ); 

I always stick this as one line. Now params has the vars:

params={};location.search.replace(/[?&]+([^=&]+)=([^&]*)/gi,function(s,k,v){params[k]=v}) 

multi-lined:

var params={}; window.location.search .replace(/[?&]+([^=&]+)=([^&]*)/gi, function(str,key,value) { params[key] = value; } ); 
deleted 2 characters in body
Source Link
AwokeKnowing
  • 8.3k
  • 9
  • 40
  • 49

I always stick this as one line. Now params has the vars:

var params={};window.location;location.search.replace(/[?&]+([^=&]+)=([^&]*)/gi,function(strs,keyk,valuev){params[key] = value;params[k]=v;}); 

multi-lined:

var params={}; window.location.search .replace(/[?&]+([^=&]+)=([^&]*)/gi, function(str,key,value) { params[key] = value; } ); 

I always stick this as one line. Now params has the vars:

var params={};window.location.search.replace(/[?&]+([^=&]+)=([^&]*)/gi,function(str,key,value){params[key] = value;}); 

multi-lined:

var params={}; window.location.search .replace(/[?&]+([^=&]+)=([^&]*)/gi, function(str,key,value) { params[key] = value; } ); 

I always stick this as one line. Now params has the vars:

params={};location.search.replace(/[?&]+([^=&]+)=([^&]*)/gi,function(s,k,v){params[k]=v;}); 

multi-lined:

var params={}; window.location.search .replace(/[?&]+([^=&]+)=([^&]*)/gi, function(str,key,value) { params[key] = value; } ); 
to better see the beauty of the solution
Source Link
Qwerty
  • 32.5k
  • 26
  • 131
  • 159
Loading
Source Link
AwokeKnowing
  • 8.3k
  • 9
  • 40
  • 49
Loading