splitting URL to get ids

Alex Lord
Alex Lord used Ask the Experts™
on
/contact.php?eid=667395&cid=2058709&id=53296&f=1

Open in new window



Above is the end part of my url for a project

it is created from clicking to my contact page from another which generates 3 ids,

how can i use js or jq to extract these 3 ids from the url ?

kinda lost on the direction to go.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Chief Technology Ninja
Distinguished Expert 2018
Commented:
Hi Alex,

You can use Window.Location.Search to get
eid=667395&cid=2058709&id=53296&f=1

Open in new window

and then you can use

var query = "eid=667395&cid=2058709&id=53296&f=1";
var parts = query.split("&");
alert(parts[0]);
alert(parts[1]);
alert(parts[2]);

Open in new window


And if you just need to extract the values, you can split using = after you have extracted individual key-value pair.

Regards,
Chinmay.

Author

Commented:
Thank you :)
Chinmay PatelChief Technology Ninja
Distinguished Expert 2018

Commented:
Glad I could help :)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial