Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

christianjul commented Feb 2, 2014

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