javascript – Save in localstorage and db and show it later

Question

I am not one of the people who wants to get something without doing anything, but this time I need your help urgently.

I use Elementor Pro. I have a button that is limited to 7 clicks, when clicking number 7 is disabled, and this is saveed in localstorage to display later. My problem if the user login from diferent device, the count start againg in 0. and obviously the code don’t work for my need, The user after 7 click Never can click again.

How can resolve this, please any idea?

this is the code… Thank You Advances and Cheers to All.

window.addEventListener("load", ()=>{
 // Read the saved state from local storage (if not yet saved, will be null)
 let clickcount3 = localStorage.getItem("localStorage.clickcount3");

 if(localStorage.clickcount3>6)
     document.getElementById("showResultMasPack").style.visibility = "visible";

});
 
function CounterMastPack() {
if (typeof(Storage) !== "undefined") {
 if (localStorage.clickcount3) {
   localStorage.clickcount3 = Number(localStorage.clickcount3)+1;
 } else {
   localStorage.clickcount3 = 1;
 }
 document.getElementById("resultMastPack").innerHTML = localStorage.clickcount3 + " Click(s).";
} else {
 document.getElementById("resultMastPack").innerHTML = "Sorry, your browser does not support web storage...";
}
if(localStorage.clickcount3>6)
document.getElementById("showResultMasPack").style.visibility = "visible";      
}```

0
Tony Abaroa 3 weeks 2021-09-03T16:57:04-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse