more thorough tests for localStorage presence

This commit is contained in:
ansuz 2017-06-13 11:57:21 +02:00
parent 100cc1792a
commit 3337e2133a

View File

@ -20,16 +20,24 @@ define([], function () {
};
}
if (!localStorage || typeof(localStorage.getItem) !== 'function') {
require('jquery', function ($) {
var failStore = function () {
require(['jquery'], function ($) {
$.ajax({
type: 'HEAD',
url: '/common/feedback.html?NO_LOCALSTORAGE=' + (+new Date()),
});
});
window.alert("CryptPad needs localStorage to work, try a different browser");
return;
};
try {
var test_key = 'localStorage_test';
var testval = Math.random().toString();
localStorage.setItem(test_key, testval);
if (localStorage.getItem(test_key) !== test_key) {
return failStore();
}
} catch (e) { console.error(e); return failStore(); }
require([document.querySelector('script[data-bootload]').getAttribute('data-bootload')]);
});