My Account   Contact Us    
  
» HomeProductsSupportDeveloper CommunityCompany
Get Query String variables in JavaScript
Author: Pete Freitag
Category: JavaScript
Use Java Script to get access to the query string
<script>
function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  } 
  alert('Query Variable ' + variable + ' not found');
}
</script>

Now make a request to page.html?x=Hello

<script>
  alert( getQueryVariable("x") );
</script>


Content Management Powered by ActivEdit  ActivEdit Browser Based WYSIWYG HTML Editor

More Code Samples

Sign up for our newsletter: | Subscribe with RSS: RSS
© ActivSoftware 1999 to 2005 | Privacy Statement