A
A
Alexander Yank2016-06-04 14:41:51
JavaScript
Alexander Yank, 2016-06-04 14:41:51

Why doesn't the jquery cookie condition fire when the modal closes?

After 2 seconds of being on the page, a modal window opens, and if I close it or click on the "order" button, it no longer pops up, even if I reload the page or go to another one (jquery cookie). But the condition I wrote doesn't work, the question is why?

jQuery.noConflict();

    jQuery(document).ready(function() {

      jQuery('.btn-primary').click(function() {
        jQuery.cookie('back_call', '1', {
          expires: 1,
          path: '/'
        });
      });
      jQuery('.close span').mouseover(function() {
        jQuery.cookie('back_call2', '2', {
          expires: 1,
          path: '/'
        });
      });

      function showmodal() {
        if (jQuery.cookie('back_call') != 1) {
          jQuery("#dialog").modal('show')
        } else if (jQuery.cookie('back_call2') != 1) {
          jQuery("#dialog").modal('show')
        }
      }
      setTimeout(showmodal, 2000);

    });

You can see it on a blank page (not advertising) artlenk.ru/project/vip

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Kalibrov, 2016-06-04
@alex-lenk

An error in the logic of the conditions.
1. When you click on "close", "2" is written in the cookie, and in the condition you check !=1. "2" is never equal to "1", so you will always get the window opened.
2. In addition to this, the conditions work sequentially, so that in order for the window not to appear, the user will need to close the window at least once and click on "waiting for a call" at least once

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question