javascript - Using location.search to locate a parameter's value -
javascript - Using location.search to locate a parameter's value -
im working on tool takes value parameters in url , few things them.
my issue is, cant seem utilize document.location show specific value im after, example:
www.examplesite.com?yourname=gilgilad
i want utilize document.location.search , set in var, need var's value "gilgilad"
i read on location.search in w3school , tired looking similar questions on here seems no 1 has specific need.
is doable using location.search? give thanks you.
location.search homecoming after question mark including it. there universal js value of first parameter (even if url has more parameters):
var want = location.search.split("&")[0].replace("?","").split("=")[1] example: lets take url http://example.com?name=jon&country=us
location.search equal ?name=jon&country=us .split("&")[0] splits 2 strings (?name=jon , country=us) , takes first one .replace("?","") removes ?, ?name=jon becomes name=jon .split("=")[1] splits name=jon name , jon , takes sec one. done! javascript location
Comments
Post a Comment