Skip to content

Instantly share code, notes, and snippets.

@vinicius-stutz
Last active March 16, 2016 18:51
Show Gist options
  • Save vinicius-stutz/40270751e28d04c06320 to your computer and use it in GitHub Desktop.
Save vinicius-stutz/40270751e28d04c06320 to your computer and use it in GitHub Desktop.
Query string via JavaScript

How to make query string in JavaScript

This is an equivalent function to the method of C# Request.QueryString, in order to return the URL parameters derived

// Equivalent function to Request.QueryString (C#) to get the URL parameters
function queryString(key) {
var re = new RegExp('(?:\\?|&)' + key + '=(.*?)(?=&|$)', 'gi');
var r = [], m;
while ((m = re.exec(document.location.search)) != null) r.push(m[1]);
return r;
}
// How to call
var id = queryString('id');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment