Skip to content

Instantly share code, notes, and snippets.

@mota57
Last active October 26, 2017 23:48
Show Gist options
  • Save mota57/4d349ffc887128288fce5c12edf0503d to your computer and use it in GitHub Desktop.
Save mota57/4d349ffc887128288fce5c12edf0503d to your computer and use it in GitHub Desktop.
Useful and minimal function to get the values of the query string. Not jQuery or dependency need it
var getQueryVal = function(str) {
s = window.location.href;
var regexstr = new RegExp(str+'=','i');
if (s.indexOf('?') !== -1) {
var result = s.substr(s.indexOf('?')+1,s.length).split('&').find(x => x.match(regexstr));
if(result){
return result.split('=')[1];
}else{
return null;
}
} else {
return null;
}
}
# example:
path=%2FSISPACOWebApp%2FOld_App_Code%2FStartup.cs&gridItemType=2&mpath=%2FSISPACOWebApp%2FOld_App_Code%2FStartup.cs&opath=%2FSISPACOWebApp%2FOld_App_Code%2FStartup.cs&mversion=GC6511bd0429e48084e6bc9f6b4d6ccea0506d3901&oversion=GC72139ede91a45f523d7883f008ce413fbd92bb01&diffParent=diffparent1&_a=compare
getQueryVal('path') //output %2FSISPACOWebApp%2FOld_App_Code%2FStartup.cs
getQueryVal('gridItemType' //output "2"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment