xxxxxxxxxx
// Easy Way - how to add parameters to url javascript
const MyURL = new URLSearchParams(window.location.search);
MyURL.set('Name', 'HazaaZOOZ');
window.location.search = MyURL;
xxxxxxxxxx
function setQueryStringParameter(name, value) {
const params = new URLSearchParams(window.location.search);
params.set(name, value);
window.history.replaceState({}, "", decodeURIComponent(`${window.location.pathname}?${params}`));
}
xxxxxxxxxx
function setUrlParam(param, value) {
const url = new URL(window.location.href);
url.searchParams.set(param, value);
window.history.pushState({}, "", url);
}
function deleteUrlParam(param) {
const url = new URL(window.location.href);
url.searchParams.delete(param);
window.history.pushState({}, "", url);
}
xxxxxxxxxx
let params = new URLSearchParams(window.location.search);
console.log(params.get(name));
xxxxxxxxxx
function storeFilter(filterName, filtervalue) {
const urlParams = new URLSearchParams(window.location.search);
urlParams.set(filterName, filtervalue);
history.replaceState(null, '', `${window.location.pathname}?${urlParams.toString()}`);
}
xxxxxxxxxx
you can use backticks ``
// url params
const elemA = "Los Angelis";
const elemB = "London";
window.location.href = `http://www.gorissen.info/Pierre/maps/googleMapLocation.php?lat=${elemA}&lon=${elemB}&setLatLon=Set`;