For example we are accessing the below URL where we have two URL parameters present, and we want to read the source and location values from given or any URL.
https://javascript.jorvee.com/geturlparams.html?source=blog&location=javadeveloper
const urlParams = Object.fromEntries(new URLSearchParams(window.location.search).entries());
All the URL parameters are now present as an object in urlParams constant. Now to access any url parameter, just access using urlParams.<name of the parameter>.
e.g. var urlSource = urlParams.source;
Here, source is a url parameter and it will return "blog" as source value.
No comments:
Post a Comment