Cookie based alert

I have this alert system that I’d like to stay closed all over the website, if the user closes it at any point. It works but with some issues.
1. If you close it on the Homepage, it still show up on other pages. You have to close it on that secondary page for it to stay closed until the browser is closed.

2. If you refresh the page or switch pages before closing the alert, it stays closed until the browser is closed.

Note: It should stay closed until the browser is closed and re-opened. My code sample is as shown below

function closeBox(){    
      
        var closeBox = $('#alert1').hide();
    // - Notice how we pass a function and get an integer
        $.cookie('closeBox', "true", {
        path: '/'});
        console.log('closeBox');
        
    }
    
    // - Simply checks the alert box above
    if($.cookie('closeBox') === "true"){
        console.log('Closing the alert box automatically...');
        closeBox();
        
    }
    
        // Close the box on click
    $('#alert1 .alert-switch').click(function () {
    console.log('Closing the alert box manually');
                      closeBox();
        
    });

Try removing the path from the cookie and see if that makes a difference.

Okay. I’ll try that and get back to you.

@felgall That did not do it.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.