1// www.example.com/users?token=12345
2
3let params = (new URL(document.location)).searchParams;
4let token = params.get("token");
5// 12345
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