How do I parse an URL with JavaScript (also with jQuery)?
For instance I have this in my string,
url = "http://example.com/form_image_edit.php?img_id=33"
I want to get the value of img_id
I know I can do this easily with PHP with parse_url()
, but I want to know how it is possible with JavaScript.
Try this:
Existing good jQuery plugin Purl (A JavaScript URL parser).This utility can be used in two ways - with jQuery or without...
I wrote a javascript url parsing library, URL.js, you can use it for this.
Example:
You can use the jquery plugin http://plugins.jquery.com/url.
$.url("?img_id")
will return33
You can use a trick of creating an
a
-element, add the url to it, and then use its Location object.Which will output:
?img_id=33
You could also use php.js to get the parse_url function in JavaScript.
Update (2012-07-05)
I would recommend using the excellent URI.js library if you need to do anything more than super simple URL handling.
got it from google, try to use this method