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>
ActivEdit Browser Based WYSIWYG HTML Editor
More Code Samples