0

I have this script and it works in half; The loader displaying in all pages but I want to show it only in home for first access.

sessionStorage.setItem('visited' , false);        
var visited = sessionStorage.getItem('visited');
if (visited != true) {
    jQuery(window).load(function() {
        jQuery(".famous-loader-overlay").delay(1500).fadeOut(1500);
    });
} else {
    jQuery(window).load(function() {
        jQuery(".famous-loader-overlay").hide();
    });
}
sessionStorage.setItem('visited', true);
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103

2 Answers2

2

Session storage keep data in string so you get always false. Try:

visited != "true"
4b0
  • 21,981
  • 30
  • 95
  • 142
0

hide it in case it's just visited and set visited only if it was not

jQuery(window).load(function() {
    if (sessionStorage.getItem('visited')) {
        jQuery(".famous-loader-overlay").hide();
        return;
    }
    jQuery(".famous-loader-overlay").delay(1500).fadeOut(1500);
    sessionStorage.setItem('visited', "1");
});
simonecosci
  • 1,194
  • 7
  • 13
  • thanks! It work but after the first show in the other pages it is shown for a moment before disappearing, how I can fix it? Thanks – p.perfetto993 Nov 05 '18 at 14:33