dimanche 1 mars 2020

Javascript localStorage.clear not working

I have this function that returns some info from a form when I press control and I need it to clear when I press ALT but it doesn't work and I don't know what I'm doing wrong any Idea?

  function key(event){
    key = event.which || event.keyCode;
    if(key==17){
        console.log("ID:"+id,"Nom: "+localStorage.getItem("name")+" coordX: "+x1+" coordY: "+y1);
        console.log("ID:"+id,"Cognom: "+localStorage.getItem("surname")+" coordX: "+x2+" coordY: "+y2);
        console.log("ID:"+id,"Email: "+localStorage.getItem("email")+" coordX: "+x3+" coordY: "+y3);
        console.log("ID:"+id,"Comentari: "+localStorage.getItem("review")+" coordX: "+x4+" coordY: "+y4);
    }
    else if(key==18){
        window.localStorage.clear();
    }

}

The first part works perfectly, it's just the localStorage.clear() that doesn't work.

Aucun commentaire:

Enregistrer un commentaire