on-internet
← Community

HTML5 LocalStorage: Checking if a key exists [duplicate]

Stack Overflow ·

Why doesn't this work? if(typeof(localStorage.getItem("username"))=='undefined'){ alert('no'); }; The goal is to redirect the user from the index page to the login page if not already logged. Here the localStorage.getItem("username")) variable is currently not defined. It's for an iOS phonegap app.

Comments

Sign in or sign up to comment and upvote.

No comments yet.