Categories
JavaScript Answers

How to detect if browser supports HTML5 Local Storage with JavaScript?

Spread the love

Sometimes, we want to detect if browser supports HTML5 Local Storage with JavaScript.

In this article, we’ll look at how to detect if browser supports HTML5 Local Storage with JavaScript.

How to detect if browser supports HTML5 Local Storage with JavaScript?

To detect if browser supports HTML5 Local Storage with JavaScript, we check if Storage is defined.

For instance, we write

if (typeof Storage !== "undefined") {
  // ...
} else {
  // ...
}

to check if Storage isn’t undefined with typeof Storage !== "undefined".

If it’s true, then local storage is available.

Otherwise, it’s not available.

Conclusion

To detect if browser supports HTML5 Local Storage with JavaScript, we check if Storage is defined.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *