Skip to content

Instantly share code, notes, and snippets.

@wehmoen
Created November 19, 2014 14:29
Show Gist options
  • Save wehmoen/9bb929cc4598ebbb86fa to your computer and use it in GitHub Desktop.
Save wehmoen/9bb929cc4598ebbb86fa to your computer and use it in GitHub Desktop.
window.location.getParam = function(name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
result = regex.exec(window.location.search);
if (result == null) {
return false;
}
return decodeURIComponent(result[1].replace(/\+/g, ' '));
};
/*
Example url: http://my-new-page.com/?page=home&article=4&title=Cake
Example use:
var page = window.location.getParam("page");
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment