Last active
October 26, 2017 23:48
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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