Parse Search String

Home

This JavaScript will parse any search string (the bit in the URL to the right of "?") and automatically declare all search parameters as JavaScript variables with values. It handles both numeric and string variable types correctly.

Paste it at the top of the head section of your page.

<script>
if (location.search.length > 0) {
  launchString = location.search.substring(1, location.search.length);
  var launchStringArray = launchString.split("&");
  for (var i = 0; i <= launchStringArray.length - 1; i++) {
    var left = launchStringArray[i].substring(0, launchStringArray[i].indexOf("="));
    var right = launchStringArray[i].substring(launchStringArray[i].indexOf("=") + 1, launchString.length);
    if (isNaN(right)) {
      right = '"' + right + '"';
    }
    eval("var " + left + " = " + right);
  }
}
</script>