1

I have 5 pages and I am including a banner in the 1st page, if the user closes the banner in 1st page then the banner should not appear in the other pages too.

$(document).ready(function(){

      $(".alert-banner-hide").on("click", function(){
            $("#alert-banner-container").hide();
      });

});

Could you please help me on this? Thanks in advance.

Abdennour TOUMI
  • 87,526
  • 38
  • 249
  • 254
San
  • 23
  • 6

1 Answers1

2

Use sessionStorage Object to have something stateful :

For On-close Banner event :

  $(".alert-banner-hide").on("click", function(){
        $("#alert-banner-container").hide();
        sessionStorage.setItem("banner-closed","yes"); //add this instruction
  });

And

on Pages load / Document ready :

  // Copy/Paste the whole code below & don't worry 
  $(function(){
         if (sessionStorage.getItem('banner-closed')==="yes"){
              //trigger close banner
             $("#alert-banner-container").hide();
         }
    })
Abdennour TOUMI
  • 87,526
  • 38
  • 249
  • 254
  • 1
    Thank you so much, Its working fine, Could you please share any url to learn JavaScript and jQuery for beginner. – San Jun 11 '16 at 02:11
  • @San : "JS essential Training Simon Allardice" put it in google & enjoy.. Good training ! – Abdennour TOUMI Jun 13 '16 at 03:07
  • Need a clarification, When I right click and open in new tab, still the banner is appearing. In same tab its working fine. – San Jun 13 '16 at 15:43