You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can check for localStorage with a one-liner like
varhasLocalStorage=!!(window.localStorage);
The !! turns whatever window.localStorage returns into a boolean, kind of like (bool) $myVar in PHP.
This should work in most cases, anyway you may want to check if localStorage is native or not, so the whole script might look like this:
varhasLocalStorage=(function(window,document,undefined){varhasStorage=window.localStorage;varisNative;// when there's nothing assigned to window.localStorage// return false because there's no localStorageif(!hasStorage){returnfalse;}// This code only gets executed when the above is true, so localStorage is supported// Native window.localStorage returns "[object Storage]" when toString() is used// the indexOf('[object Storage]') > -1 returns true if "[object Storage]" is found and// false if not. isNative=window.localStorage.toString().indexOf('[object Storage]')>-1;if(isNative){returntrue;}else{// handle non-native implementation? Maybe return -1 or whatever.return-1;}}(window,document));// Exampleif(hasLocalStorage>-1){// SUPPORTED \o/}else{window.localStorage=function(){ ... }}
very very very important!
The text was updated successfully, but these errors were encountered: