Wednesday 29 March 2017

javascript - jQuery fallback when localStorage/sessionStorage is disabled



I have a REST based service architecture. One service is used to login users. A successful login request results in a auth_token sent back to the web client.



I would like to store the token in localStorage which is working fine in most situations. However it is possible that the user disables localStorage or the browser is in private mode (as far as I know only an issue on Safari).




My question is: Is there any concept I can use as a fallback when localStorage is not available?



Is storing the token in the window variable an option?



Any ideas are appreciated.


Answer



Checkout this link to find whether you have local storage enabled or not.



https://mathiasbynens.be/notes/localstorage-pattern




Also, for the fallback you can use cookies always. Or even if the cookies is not enabled, the only way to support is by URL param. Usually, in these cases people will show a warning message staing their Localstorage/Cookie should be enabled in order to work with their site. Hope it helps .



Alternatively, you can store in window.name which will be carried over on one browser tab; if you open the same page on anther tab it wont be available.


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...