Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christianjul/8771586 to your computer and use it in GitHub Desktop.
Save christianjul/8771586 to your computer and use it in GitHub Desktop.
Very generic but working implementation of session storage fallback for safari in privacy mode
submission = {
handle: function (event) {
event.preventDefault();
event.stopPropagation();
var id,
data,
storage = submission.getStorage(),
nextUrl;
data = storage.getItem('Opeepl');
if (data === null) {
data = {};
} else {
data = JSON.parse(data);
}
id = $('[name*=__identity]').val();
data[id] = $(this).serializeArray();
storage.setItem('Opeepl', JSON.stringify(data));
nextUrl = OPEEPL.next(data[id]);
if (nextUrl) {
window.location.replace(nextUrl);
} else {
storage.clear();
OPEEPL.submit(data);
}
return false;
},
sessionStorageAvailable: function () {
var storageTestKey = 'sTest',
storage = sessionStorage;
try {
storage.setItem(storageTestKey, 'test');
storage.removeItem(storageTestKey);
return true;
} catch (e) {
// Just in case this isnt only ios specific we log it
// if (e.code !== 22 && storage.length === 0) {
// throw e;
// }
track(e);
return false;
}
},
getStorage: function () {
var storage;
if (submission.sessionStorageAvailable()) {
storage = sessionStorage;
} else {
storage = {
getItem: function (name) {
var value;
//just ignore name for now
if (window.name.length === 0) {
value = null;
} else {
value = window.name;
}
return value;
},
setItem: function (name, data) {
window.name = data;
},
clear: function () {
window.name = '';
}
};
}
return storage;
}
@christianjul
Copy link
Author

part of larger script, but shows the concept.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment