Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save samarulrajt/c88d0ef73398793af0093d2eb7a70a4c to your computer and use it in GitHub Desktop.
Save samarulrajt/c88d0ef73398793af0093d2eb7a70a4c to your computer and use it in GitHub Desktop.
Verify if PRIVATE BROWSING is blocking local storage
<!-- ERROR FOR BLOCKED LOCAL STORAGE -->
<div id="apple_storage" style="display:none;">
<div class="modal-new alerts">
<h2>Attenion</h2>
<a href="" class="close" onclick="document.getElementById('apple_storage').style.display = 'none';">Close</a>
<div class="body">
<p>
Dear customer, to ensure proper use of the site it is necessary to abandon the
private browsing.
</p>
</div><!-- /.body -->
</div>
</div>
<!-- ERROR FOR BLOCKED COOKIES -->
<div id="no_cookie" style="display:none;">
<div class="modal-new alerts">
<h2>Attenion</h2>
<a href="" class="close" onclick="document.getElementById('no_cookie').style.display = 'none';">Close</a>
<div class="body">
<p>
Dear customer, to ensure proper use of the site it is necessary to enable cookies.
</p>
</div><!-- /.body -->
</div>
</div>
<!-- Verify if PRIVATE BROWSING is blocking local storage -->
<script>
var hasStorage = function() {
var mod,
result;
try {
mod = new Date;
localStorage.setItem(mod, mod.toString());
result = localStorage.getItem(mod) === mod.toString();
localStorage.removeItem(mod);
return result;
} catch (_error) {
return false;
}
},
hasCookies = function() {
var cookieEnabled = navigator.cookieEnabled ? true : false;
if (typeof navigator.cookieEnabled == 'undefined' && !cookieEnabled) {
document.cookie = 'testcookie';
cookieEnabled = (document.cookie.indexOf('testcookie') != -1) ? true : false;
}
return cookieEnabled;
};
if (!hasStorage()) {
document.getElementById('apple_storage').style.display = 'block';
} else if (!hasCookies()) {
document.getElementById('no_cookie').style.display = 'block';
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment