Skip to content

Instantly share code, notes, and snippets.

@jerrybendy
Last active January 3, 2021 03:43
Show Gist options
  • Save jerrybendy/d9f76553ca42907cc95bb342e87beae2 to your computer and use it in GitHub Desktop.
Save jerrybendy/d9f76553ca42907cc95bb342e87beae2 to your computer and use it in GitHub Desktop.
Get parameter from URL query(search) string
/**
* 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]);
};
@gaurak
Copy link

gaurak commented Mar 26, 2019

how to use this

@gaurak
Copy link

gaurak commented Mar 26, 2019

example??

@jerrybendy
Copy link
Author

var id = getQueryString('id')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment