1// https://testsite.com/users?page=10&pagesize=25&order=asc
2const urlParams = new URLSearchParams(window.location.search);
3const pageSize = urlParams.get('pageSize');
1const queryString = window.location.search;
2const urlParams = new URLSearchParams(queryString);
3const code = urlParams.get('code')
1let params = {};
2window.location.search.slice(1).split('&').forEach(elm => {
3 if (elm === '') return;
4 let spl = elm.split('=');
5 const d = decodeURIComponent;
6 params[d(spl[0])] = (spl.length >= 2 ? d(spl[1]) : true);
7});
8
9// https://example.com/?foo=bar&best%20food=D%C3%B6ner
10params['foo'] // bar
11params['best food'] // Döner
1var getParams = function (url) {
2 var params = {};
3 var parser = document.createElement('a');
4 parser.href = url;
5 var query = parser.search.substring(1);
6 var vars = query.split('&');
7 for (var i = 0; i < vars.length; i++) {
8 var pair = vars[i].split('=');
9 params[pair[0]] = decodeURIComponent(pair[1]);
10 }
11 return params;
12};