Last active
January 3, 2021 03:43
-
-
Save jerrybendy/d9f76553ca42907cc95bb342e87beae2 to your computer and use it in GitHub Desktop.
Get parameter from URL query(search) string
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
/** | |
* Get parameter from URL query(search) string | |
* | |
* Example: | |
* ``` | |
* var id = getQueryString('id') | |
* ``` | |
* | |
* @param {string} name | |
* @returns {string} | |
*/ | |
function getQueryString(name) { | |
var result = location.href.match(new RegExp("[\?\&]" + name + "=([^\&]+)", "i")); | |
if (result == null || result.length < 1) { | |
return ""; | |
} | |
return decodeURIComponent(result[1]); | |
}; |
example??
var id = getQueryString('id')
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how to use this