To getting the query string values in JavaScript you can use URLSearchParams which is simple and has good browser support. You can use the below-mentioned code:-
const urlParams = new URLSearchParams(window.location.search);
const myParam = urlParams.get('myParam');
You can directly use the JavaScript there is no need of JQuery see the below-mentioned code:-
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, '\\$&');
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'), results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, ' '));
}
Enroll in our web development course to become as an Expert in Web Development!