LocalStorage does not work on mobile?
11,413
The beforeunload
event does not fire on iOS.
It looks like unload
does fire, so try storing your data into local storage there instead.
Alternatively, you could store data into local storage as the user edits the form (ie when each input fires change
), which comes with the added bonus of storing the entered data even if the browser crashes before the user finishes.
Comments
-
AndrewLeonardi almost 2 years
I'm using localStorage to back up form data on a long form. So if a user refreshes they will not lose everything. This is working perfectly on Chrome & Firebox on the computer.
However on mobile (iOS at least) It's not working at all. Any advice?
Here is a small part of my code as an example:
Storing Data:
window.onbeforeunload = function() { window.localStorage.setItem("Job1", $("#topScore1B").text()); }
Retrieving Data:
window.onload = function() { // If values are not blank, restore them to the fields var name = window.localStorage.getItem('Job1'); if (name !== null) $('#job1').text(name); }