0

I seem to not be able to find implementation from the common Ajax libraries (JQuery, mootools, prototypejs...) that would allow the operation of parsing the window.location.href for request parameter. I would expect something like:

$P{"param1"} == "param1_value"

Am I missing something?

p.s. The web does contains implementation examples for such operations

Sean Kinsey
  • 37,689
  • 7
  • 52
  • 71
Maxim Veksler
  • 29,272
  • 38
  • 131
  • 151

1 Answers1

0

It's really easy in vanilla javascript

var Query = (function(){
    var query = {}, pair, search = location.search.substring(1).split("&"), i = search.length;
    while (i--) {
        pair = search[i].split("=");
        query[pair[0]] = decodeURIComponent(pair[1]);
    }
    return query;
}());


alert(Query["foo"]);
Sean Kinsey
  • 37,689
  • 7
  • 52
  • 71
  • cool! And it works for all the cases I can think of :) Could you please explain the code? I'm not a javascript programmers and there are lots of things I'm not clear about, for example what does location.search reference? What does decodeURIComponent() do? Comments for logic would be very helpful here... – Maxim Veksler Jun 12 '10 at 19:18