V
V
vasilseodor2015-05-15 14:37:04
JavaScript
vasilseodor, 2015-05-15 14:37:04

How to open modal once and only after 30 seconds?

There is a modal window - code .
1) How to make it so that it opens only after 30 seconds
2) How to make it not appear again when the page is reloaded. That is, the session or cookies are remembered, as it were. When switching to other pages, the window should no longer pop up.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Mikhail Osher, 2015-05-15
@miraage

jQuery(function($) {
  // Ключ localStorage
  var LS_KEY = 'modal_shown';
  
  // Если модал еще не открыали
  if (!localStorage.getItem(LS_KEY)) {
    setTimeout(function() {
      // Открываем модал
      modalShownFn();
      
      // Сохраняем флаг в localStorage
      localStorage.setItem(LS_KEY, '1');
    }, 30 * 1000);
  }
});

D
Denis Ineshin, 2015-05-15
@IonDen

To open after 30 seconds: setTimeout
To remember what has already been opened, you need to write a variable, say, in cookies: popup_opened=true;
This can be done, for example, with: jQuery Cookie
And then, when trying to reopen the popup, check for the presence of this variable.

P
Papa, 2015-05-15
Stifflera @PapaStifflera

stackoverflow.com/questions/13352658/reveal-modal-...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question