V
V
vasilseodor2017-03-23 15:22:57
JavaScript
vasilseodor, 2017-03-23 15:22:57

How to show a message on a jquery cookie for a while?

There is a block with the message class that is shown to new visitors (by cookie, by adding display:block;). If the visitor already has a cookie, then the block is hidden by adding display:none;.
<div class="message">Сообщение</div>

$(function() {
    if (!$.cookie('message')) {
        $('.message').css({
            'display': 'block'
        });
    }
    else {
    	$('.message').css({
            'display': 'none'
        });
    }
    $.cookie('message', true, {
        expires: 7,
        path: '/'
    });
});
setTimeout(function(){$('.message').fadeOut()}, 7200000);


But how do you make the message only show for 2 hours to the user (even if they already have a cookie) and then disappear (by adding display:none;)?
The problem is that for the user with the cookie, the message is wrapped in display:none;, but it needs to be wrapped only after a while.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question