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.