function uniqueID() { let s4 = () => { return Math.floor((1 + Math.random()) * 0x10000) .toString(16) .substring(1); } return s4() + s4() + '-' + s4() + '-' + s4(); } var getUrlParameter = function getUrlParameter(sParam) { var sPageURL = window.location.search.substring(1), sURLVariables = sPageURL.split('&'), sParameterName, i; for (i = 0; i < sURLVariables.length; i++) { sParameterName = sURLVariables[i].split('='); if (sParameterName[0] === sParam) { return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]); } } return false; } var data; var timesUnique = new Date().valueOf(); if (!getUrlParameter('id')) { data = uniqueID(); if (window.location.href.includes('?')) { window.location.href = window.location.href + `&id=${data}-${timesUnique}`; } else { window.location.href = window.location.href + `?id=${data}-${timesUnique}`; } } else { if (history.pushState) { data = uniqueID(); var newurl = window.location.protocol + "//" + window.location.host + window.location.pathname + `?id=${data}-${timesUnique}`; window.history.pushState({path:newurl},'',newurl); } }