Thursday, 15 April 2010

javascript - How to get the value from the URL parameter? -



javascript - How to get the value from the URL parameter? -

i have url parameter follows,

www.test.com/t.html?a=1&b=3&c=m2-m3-m4-m5

i need whole value of c. tried read url, got m2. how do using javascript?

javascript has nil built in handling query string parameters.

you access location.search, give ? character on end of url or start of fragment identifier (#foo), whichever comes first.

this suggests have written (or found 3rd party) code reading query string , accessing bit want - haven't shared us, hard wrong it.

the code utilize this:

var querystring = function () { // function anonymous, executed , // homecoming value assigned querystring! var query_string = {}; var query = window.location.search.substring(1); var vars = query.split("&"); (var i=0;i<vars.length;i++) { var pair = vars[i].split("="); // if first entry name if (typeof query_string[pair[0]] === "undefined") { query_string[pair[0]] = decodeuricomponent(pair[1]); // if sec entry name } else if (typeof query_string[pair[0]] === "string") { var arr = [ query_string[pair[0]],decodeuricomponent(pair[1]) ]; query_string[pair[0]] = arr; // if 3rd or later entry name } else { query_string[pair[0]].push(decodeuricomponent(pair[1])); } } homecoming query_string; }();

you can access querystring.c

javascript url

No comments:

Post a Comment