How To Explicitly Request End User To Not Remove Local Storage Data?
Solution 1:
You can't prevent the user from deleting their data, from their web browser (because it is their web browser).
There are no local databases to which that rule does not apply.
If you want to protect against accidental deletion of data: Sync it to a user account on your server.
Solution 2:
I believe what you are looking for is navigator.storage.persist(). It will not prevent the user from deleting the data (because that would be a major security breach), but it will, essentially, inform the browser that the data must not be deleted because the data cannot be refetched/regenerated from the server. The below code snippet will accomplish what you are after in supporting browsers.
"use strict"; // always put this just once at the start of all javascript filesfunctionpersistStorage(thenFunc) {
thenFunc = thenFunc || function(success){
if (!success) console.error("Failed to request persistant storage!");
};
if (
typeof navigator === "object" &&
typeof navigator.storage === "object" &&
typeof navigator.storage.persist === "function"
) {
navigator.storage.persist().then(
thenFunc.bind(0, true),
thenFunc.bind(0, false)
);
} else {
thenFunc(false)
}
}
Then, call function persistStorage
, optionally with a callback that is passed true
if it succeeds, to persist your storage.
Solution 3:
As far as I know, there is no way of preventing a user from deleting local data from the browser (and there should not be one, in my opinion).
If you really want to be sure to preserve your data, you should sync them with your server.
Solution 4:
If user clear all the browser data there is no option to retain the local storage. It is up to their choice.
There are storage like webSQL, indexedDB in webkit enabled browsers but if they select to remove site data while clearing the browser the data will loss.
In chorme the checkbox "cookie and site plugin data" in the "clear browsing data menu" will decide to remove all site data.
Thanks, MG
Post a Comment for "How To Explicitly Request End User To Not Remove Local Storage Data?"