Skip to content Skip to sidebar Skip to footer

How To Check If Html Sessionstorage Is Not Empty?

G'day guys, I'm trying to figure out the best way to check for empty storageSession in HTML5. I noticed that some browser returns null and some return just empty space if you clear

Solution 1:

That should work; the problem is that you have null in quotes.

Also, sessionStorage.length will give you the number of values stored.

Solution 2:

But this is how you check for "empty" session storage

   if (sessionStorage.length == 0) {

Solution 3:

Use this to check if there is item is session storage called "name"

if (sessionStorage['name']) {
    console.log("There is 'name' in session storage ")
}

Solution 4:

You can also try

if($window.sessionStorage.value === undefined) {}

Solution 5:

i checked this way

   $(document).ready(function () {
       if (window.sessionStorage) {
           if (sessionStorage.getItem("x-mas") === null) {
               if (getCountryCode() == 'de') {
                   $('#xmasModal').modal();
                   sessionStorage.setItem("x-mas", "1")
               }
           }
       }
   });

   functiongetCountryCode() {
       var url = window.location.pathname;
       var segments = url.split('/');
       var countrycode = segments[1];
       return countrycode;
   }

Post a Comment for "How To Check If Html Sessionstorage Is Not Empty?"