D
D
Darklt2018-02-27 09:57:04
JavaScript
Darklt, 2018-02-27 09:57:04

How to enable cookie js to show message 1 time?

There is a default window script open:

<div  class="personal-data-warning" id="block_id">ОКНО<a class="black personal-data-warning-close" onclick="diplay_hide('#block_id');return false;" ></a></div>

Closure:
function diplay_hide (blockId)

{ 
    if ($(blockId).css('display') == 'none') 
        { 
            $(blockId).animate({height: 'show'}, 500); 
        } 
    else 
        {     
            $(blockId).animate({height: 'hide'}, 500); 
        }


}

I connected the jquery.cookie.min.js library
But I can’t figure out how to put $.cookie so that it is only shown to the visitor once

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Anton, 2018-02-27
@Eridani

Throw the key:value into the local storage and check this pair every time, if there is - do not show, if not - record and show

E
Evgeny Kalibrov, 2018-02-27
@rework

function diplay_hide (blockId)
{ 
    if ($.cookie('isShowPopup')) return false;
    if ($(blockId).css('display') == 'none') 
        { 
            $(blockId).animate({height: 'show'}, 500); 
            $.cookie('isShowPopup', '1');
        } 
    else 
        {     
            $(blockId).animate({height: 'hide'}, 500); 
        }


}

A
Andreo, 2018-02-27
@chupacabramiamor

Check for cookies before displaying. If they are not there, then install and show what you need there ...

if(!$.cookie('checker')) {
    $.cookie('checker', 1, {
        expires: 30
    });
    $(blockId).animate({height: 'show'}, 500);
}

For the .personal-data-warning block in css, set the property display: none

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question