A
A
Artemy Zheman2017-02-06 12:39:08
JavaScript
Artemy Zheman, 2017-02-06 12:39:08

Wordpress - how to execute a script once a day?

In general, the task is this, you need to show a popup that is called by a simple js function once a day for each visitor.
Doing so

(function ($) {
            $(function () {
                if($.cookie('pop')) {
                    console.log("Попап уже появлялся.")
                } else {
                    setTimeout(function(){
                        Popup.getShowTarget('popup__thanks'); //Функция вывода попапа
                        $.cookie('pop', 'on', { expires: 1  });
                    }, 10000)
                }
            })
        })(jQuery);


But there are problems, everything works, but when you go to another page, the cookies seem to be reset and the popup appears again, and if you update the same page, it is shown only 1 time. What are we doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2017-02-06
@lebonnet

docks
Create expiring cookie, valid across entire site:
$.cookie('name', 'value', { expires: 7, path: '/' });

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question