tags:

views:

31

answers:

2

Hi,

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

+1  A: 

You don't really to use a library; a pure javascript function like the one in the link you include should be more than enough.

Here are some options for jQuery: http://stackoverflow.com/questions/901115/get-querystring-with-jquery

mjangda
A: 

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
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