Friday, 12 October 2012

Parsing the Search String/Query String (revised)

This version avoids using the eval() function and so is neater and safer.
[Compared with the version given in an earlier note in this blog]

var GLOBAL={}

location.search.replace(
  new RegExp("([^?=&]+)(=([^&]*))?", "g"),
  function($0, $1, $2, $3) {
    GLOBAL[$1]=$3;
  }
);

No comments:

Post a Comment