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.
Worked for me. But the first var should be var url = window.location.href
This should fix a few edge-cases in kobe's answer:
One liner:
If your string is called
s
thenwill give it to you.
Something like this should work for you. Even if there are multiple query string values then this function should return the value of your desired key.
reference