Last active
September 27, 2017 20:55
-
-
Save bcls/bdb283227ea30dbab9b353c1f67a61fa to your computer and use it in GitHub Desktop.
get URL param value #javascript
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
/** | |
* gets value of a URL param if exists | |
* @param {string} name the param you want the value of | |
* @return {string} result value of param if exists or "" | |
*/ | |
function getURLparam(name) { | |
var regex, | |
results; | |
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); | |
regex = new RegExp("[\\?&]" + name + "=([^&#]*)"); | |
results = regex.exec(location.search); | |
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " ")); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment