Posts

Showing posts with the label urlparams

GET URL Parameters Using JavaScript - Web Development

Image
            What are URL parameters ? Let's say one URL of a site is like -   https://www.example.com/users?name=John&id=23 In this URL we can see that some parameters are passed as arguments at the end like (name=John and id=23) . This means that this particular URL is trying to do something with John of id 23. Now, let's say you are the host of this site. How can you GET these parameter values which are being opened by a user. To make it simple, suppose your website provides data for some names with ids. The data which you will show in your website depends on this parameters provided on the URL. Today, we will learn how to fetch them using JavaScript .      Let's fix a goal that whatever parameters of name and id value are in the URL we are to print them on the webpage. In this case, we will print John and 23 on the webpage. So, let's begin.          In JavaScript, window.location returns the URL of the location bar. We will create an URLSearchParams() object