Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What JavaScript library should I use for parsing URL parameters?

Tags:

javascript

How do I parse URL parameters in JavaScript? (These are the parameters I would ordinarily call GET parameters or CGI parameters, but in this case the page is basically submitting to itself, not a server, so there is no GET request and definitely no CGI program.)

I've seen a number of routines on the net that I can copy, but I have no idea how robust any of them are. I'm used to other languages like Perl and Java where I can rely on an extremely well-tested and robust library that I know will handle millions of little edge-cases in the standard. I would like the same here, rather than just cutting and pasting an example.

like image 926
skiphoppy Avatar asked Sep 01 '09 14:09

skiphoppy


2 Answers

jQuery URL Utils or jQuery URL Parser.

like image 92
Darin Dimitrov Avatar answered Sep 27 '22 18:09

Darin Dimitrov


Here's are two simple functions that do the job : http://adamv.com/dev/javascript/querystring

Here is a sample of the API Reference :

var qs = new Querystring();

// Parse a given querystring
var qs2 = new Querystring("name1=value1&name2=value2");

var v1 = qs2.get("name1");
var v3 = qs2.get("name3", "default value");
like image 42
Andreas Grech Avatar answered Sep 27 '22 18:09

Andreas Grech