Skip to content Skip to sidebar Skip to footer

Check Url Parameter Using Javascript

If two url are like: http://localhost:1113/Project/TestCourse.aspx?id= http://localhost:1112/Project/TestCourse.aspx How to check whether 'id' is present or not using javascript?

Solution 1:

How about:

/\?id\=|&id\=/i.test(location.href)

Solution 2:

I would tweak @KooiInc's answer to location.href.match(/(\?|&)id($|&|=)/). It catches parameters without values (for example http://localhost:1112/Project/TestCourse.aspx?id) and also ensures you only have id not just a param starting with id (e.g idparam).


Solution 3:

use location.href.match(/\?id\=/i) && location.href.match(/&id\=/i)


Post a Comment for "Check Url Parameter Using Javascript"