Check browser support for localStorage and sessionStorage

Before using local storage, how to Check browser support for localStorage and sessionStorage?

JavaScript

if(typeof(Storage) !== "undefined") {
    // Code for localStorage/sessionStorage.
    document.write("Congratulation! Your browser support Web Storage.");
} else {
    document.write("Sorry! Your browser no't support Web Storage.");
}

Preview snippets

Run Snippets
  • Share
  • Copyright 2016 by WebiBeris.com. All Rights Reserved.