I have an app that saves a user name in local storage.
It works fine with every browser except Safari
in private mode
.
Is there a way to save this variable in Safari private mode? I tried using cookies but it's also doesn't work...
Any work around?
I implemented a LocalStorageHandler that checks if the browser supports local storage, if it doesn't support then I use a Cookie.
This is the function that checks if it supports local storage:
localStoreSupport: function ()
{
var testKey = 'test', storage = window.sessionStorage;
try
{
storage.setItem(testKey, '1');
storage.removeItem(testKey);
return true;
}
catch (error)
{
return false;
}
}
And this is how I dealt with false:
if (this.localStoreSupport())
{
localStorage.setItem(name, value);
}
else
{
document.cookie = name + "=" + encodeURIComponent(value) + expires + "; path=/";
}
I hope this helps you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With