You can use feature detection to find out if sessionStorage
is available, and if not use the jQuery Cookie plugin:
var yetVisited = sessionStorage ? sessionStorage['visited'] : $.cookie('visited');
if (!yetVisited) {
$j("#adspaceModal").modal("show").on("shown", function () {
window.setTimeout(function () {
$j("#adspaceModal").modal("hide");
}, 20000);
});
// open popup
sessionStorage ? sessionStorage['visited'] = 'yes' : $.cookie('visited', 'yes');
}
In fact it's probably better to abstract it to it's own function:
function storage(key, value) {
if (!value) {
// getter
return window.sessionStorage ? window.sessionStorage[key] : $.cookie(key);
}
else {
// setter
window.sessionStorage ? window.sessionStorage[key] = value : $.cookie(key, value);
}
}