Skip to content

Instantly share code, notes, and snippets.

@r4fx
Created July 5, 2014 22:03
Show Gist options
  • Save r4fx/20bf21d76bcf3833d3eb to your computer and use it in GitHub Desktop.
Save r4fx/20bf21d76bcf3833d3eb to your computer and use it in GitHub Desktop.
get URL parameter
/*
* get URL parameter
*/
function GetURLParameter(sParam) {
var sPageURL = window.location.search.substring(1);
var sURLVariables = sPageURL.split('&');
for (var i = 0; i < sURLVariables.length; i++) {
var sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] == sParam) {
return sParameterName[1];
}
}
}
// Use example:
// http://somepage.com/contact/?formaction=callback&type=2
var formaction = GetURLParameter('formaction');
var type = GetURLParameter('formaction');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment