6

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?

1

3 Answers 3

10

How about:

/\?id\=|&id\=/i.test(location.href)
Sign up to request clarification or add additional context in comments.

Comments

8

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).

Comments

1

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

1 Comment

Would be null in the case of the 2 given urls. Change && to ||

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.