Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check url parameter using javascript

Tags:

javascript

url

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?

like image 214
ANP Avatar asked Aug 09 '10 08:08

ANP


People also ask

How do we access the URL parameters with Javascript?

For getting the URL parameters, there are 2 ways: By using the URLSearchParams Object. By using Separating and accessing each parameter pair.

How do I query a parameter in Javascript?

To parse the query parameters into an object, use URL. searchParams 's . entries() method, which returns an Iterator of key/value pairs, and Object. fromEntries to convert it into an object.

Can you use Javascript to get URL parameter values?

The short answer is yes Javascript can parse URL parameter values. You can do this by leveraging URL Parameters to: Pass values from one page to another using the Javascript Get Method. Pass custom values to Google Analytics using the Google Tag Manager URL Variable which works the same as using a Javascript function.

How do you query parameters in a URL?

Query parameters are a defined set of parameters attached to the end of a url. They are extensions of the URL that are used to help define specific content or actions based on the data being passed. To append query params to the end of a URL, a '? ' Is added followed immediately by a query parameter.


1 Answers

How about:

/\?id\=|&id\=/i.test(location.href)
like image 108
KooiInc Avatar answered Sep 27 '22 23:09

KooiInc