Click here to Skip to main content
15,886,798 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to store a localStorage value only once. If it exists in localStorage,an alert appear.
Posted
Comments
kbrandwijk 4-Sep-14 19:30pm    
I would add HTML5, and Web Storage tags to make this question easier to find.

1 solution

Check if window.localStorage.getItem('...') is null.
 
Share this answer
 
Comments
Member 10941024 5-Sep-14 17:44pm    
this is my code please check with me the value :thank you


$(".aj").click(function(){

var con = localStorage.getItem('noc');//counter for increment key
if(con!=null) {
con = parseInt(con);
} else {
con = -1;
}
con++;
localStorage.setItem('noc',con)

localStorage.setItem('nmdpdt'+parseInt(localStorage.getItem('noc')),$nnpdt);


for(i=0 ; i < localStorage.length ; i++){
key = i;
value = localStorage.getItem('nmdpdt'+i);

if(value === null){
alert("exist");
break;
}else{
alert("not exist");

}


document.write(key+"::::"+value+"</br>");



}



});
kbrandwijk 5-Sep-14 17:49pm    
I'm not sure about your question, but shouldn't the check before the alert look like: if (value != null) instead of (value === null)?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900