Get URL Parameters with JavaScript | SJB -->

This website uses cookies to ensure you get the best experience. More info...

Pages

Get URL Parameters with JavaScript

URL parameters are also called query string parameters. These carry so many important information, such as user preferences, search queries, link referrals, and many more. Use this tool to parse the parameters of a URL. Put the URL into the box and hit click to get parameters on the result section.

URL
Result will display here.
Here is the little script showing how it works. Thanks to the URLSearchParams, it has made the script a lot shorter.
1
2
3
4
5
6
7
8
function getUrlParameters(url) {
    var searchParams;
    url = new URL(url);
    searchParams = url.searchParams;
    searchParams.forEach(function(value, key) {
        console.log(value, key);
    });
};
Happy coding!

No comments:

Post a Comment