Alert box stay closed on refresh

Is there a way to set a time for the alert box to stay closed? Or even have it stay logged until next login / cleared cookies.

I see there was an old support but that is probably with the older version of the alter since I am using Pro 3.x which has a new better version with a lot better design controls.

Let me know if there is a function I can add for this would be great thanks.

Hi Quentin,

Thanks for writing in. To achieve that, first you need to add an ID to the alert box for this example I used alert1, after that add this JS code.

jQuery(function( $ ){

    $('#alert1 .close').click(function( e ){
      	/* expire in 1 day */
        $.cookie('#alert1', 'closed', { path: '/', expires: 1  }); 
    });
  
    if( $.cookie('#alert1') === 'closed' ){
        $('#alert1').hide();
    }  

});

So what it will do is add a cookie that lets the browser remember what alert box has been closed and will hide it when the site refreshes.

Hope it helps.

Looking the code is simple and should work, for some reason it doesn’t work. ¿Any clue?

Hello Armando,

You will need to add an ID to your alert box.
alert1 ID must be present in your alert box. If you forgot to add it, the code will not work.

Hope this helps.

Hello Rue, of course I add it, but it didn’t work. Nevermind I got busy with other task, but tomorrow I will check it through console to track what is happening. Thank you

Hi Armando,

Maybe there’s just a code typo. If you want, you can also share the link of your site so we can help you out. :slight_smile:

Have a great day!

Sorry got busy last week so wasn’t able to test. Added code and doesn’t seem to be working for myself either. Link to website below in secure note since site still being worked on.

Hi again Armando,

Try updating the code to

jQuery(function( $ ){

    $('#alert .close').click(function( e ){
      	/* expire in 1 day */
        Cookies.set('#alert', 'closed', { expires: 1 , path: ''});
    });
  
    if( Cookies.get('#alert') === 'closed' ){
        $('#alert').hide();
    }  

});
1 Like

Hi Albrech,

That worked thanks :slight_smile:

You’re welcome, Armando.

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