Obtenha parâmetros de consulta URL JS
const urlParams = new URLSearchParams(window.location.search);
const myParam = urlParams.get('myParam');
Embarrassed Elephant
const urlParams = new URLSearchParams(window.location.search);
const myParam = urlParams.get('myParam');
const queryString = window.location.href;
const parameters = new URLSearchParams(queryString);
const value = parameters.get('key');
function updateQueryStringParameter(uri, key, value) {
var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
var separator = uri.indexOf('?') !== -1 ? "&" : "?";
if (uri.match(re)) {
return uri.replace(re, '$1' + key + "=" + value + '$2');
}
else {
return uri + separator + key + "=" + value;
}
}
var query = new URLSearchParams();
query.append("KEY", "VALUE");
var url = "http://site.com/page?" + query.toString();