Skip to content

Instantly share code, notes, and snippets.

@tristar500
Created July 21, 2012 21:08
Show Gist options
  • Save tristar500/3157196 to your computer and use it in GitHub Desktop.
Save tristar500/3157196 to your computer and use it in GitHub Desktop.
Return a URL paramter
// url = "http://www.testing.com/page.php?text=testing&page=34";
// result = getParameterByName("text", url);
// result is "testing"
function getParameterByName(name, url){
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(url);
if(results == null)
return "";
else
return decodeURIComponent(results[1].replace(/\+/g, " "));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment