After setting a code to display a simple message and having tested it successfully in computers and tablets, I see that it does not work on Android, Iphone or Windows mobiles.
<div id="box">
<p>My message to be displayed just once on the landing page.</p>
</div>
<script>
window.onload=function(){
(function() {
var visited = localStorage.getItem('visited');
if (!visited) {
document.getElementById("box").style.display = "block";
localStorage.setItem('visited', true);
}
})();
}
</script>
It works like a charm in computer and tablet browsers.
Anything that can be done using jQuery can be done in JavaScript. I’m not the one to pick it apart for you, but I’m sure someone around here will be able to help with refactoring it.
The part of that solution that relates to localStorage is the same as in the prior version you posted - so the jQuery code has nothing to do with whether the storage commands are working or not. The only difference is that the jQuery version is set to run sooner as it only waits for the DOM to load and not all the other external files - you can get the same result with ordinary JavaScript attached to the bottom of the page if you djust run the code straight away instead of onload.