1// https://testsite.com/users?page=10&pagesize=25&order=asc
2const urlParams = new URLSearchParams(window.location.search);
3const pageSize = urlParams.get('pageSize');
1const params = new URLSearchParams(window.location.search);
2
3// Check if we have the param
4if (params.has("myParam")) {
5 console.log("Yep! We have it. Value is: " + params.get("myParam"));
6} else {
7 console.log("The param myParam is not present.");
8}
1const queryString = window.location.search;
2const urlParams = new URLSearchParams(queryString);
3const code = urlParams.get('code')
1// Example URL: https://example.com/over/there?name=ferret
2const queryString = window.location.search;
3const urlParams = new URLSearchParams(queryString);
4const parameter_name = urlParams.get('name')
5console.log(parameter_name);
1let url = 'https://www.example.com?name=n1&name=n2';
2let params = (new URL(url)).searchParams;
3params.get('name') // "n1"
4params.getAll('name') // ["n1", "n2"]
1var url_string = "http://www.example.com/t.html?a=1&b=3&c=m2-m3-m4-m5"; //window.location.href
2var url = new URL(url_string);
3var c = url.searchParams.get("c");
4console.log(c);