xxxxxxxxxx
// Get the value of a specific parameter from the URL
function getUrlParameter(parameterName) {
// Get the URL query string
var queryString = window.location.search;
// Remove the '?', if present
queryString = queryString.substring(1);
// Split the query string into an array of parameters
var parameters = queryString.split('&');
// Loop through all the parameters
for (var i = 0; i < parameters.length; i++) {
// Split each parameter into its key and value
var parameter = parameters[i].split('=');
var key = decodeURIComponent(parameter[0]);
var value = decodeURIComponent(parameter[1]);
// Check if the key matches the requested parameter name
if (key === parameterName) {
return value;
}
}
// If the parameter is not found, return null or an appropriate default value
return null;
}
// Usage example
var productId = getUrlParameter('id');
console.log(productId); // Output: The value of the 'id' parameter from the URL