Jhosman
Jhosman

Reputation: 555

Set cookie in mod Remodal When the window closes and reappears anymore

I'm using the Remodal - modal Window script, but How can I configure when that window closes it doesnot appear anymore for the visitor?

Upvotes: 0

Views: 298

Answers (2)

Darren
Darren

Reputation: 169

Using js-cookie it would work something like this:

$(document).on('closed', '.remodal', function (e) {
    console.log('closed' + (e.reason ? ', reason: ' + e.reason : ''));
    Cookies.set('remodal_closed', '1', { expires: 7 });
});

Then check that the cookie doesn't exist before opening remodal:

$(document).ready(function() {
  if(!Cookies.get('remodal_closed')) {
    setTimeout(function() {
        $('[data-remodal-id=modal]').remodal().open();
    }, 3000); //set a more realistic time
  }
});

You might also need to set the cookie on confirmation:

$(document).on('confirmation', '.remodal', function () {
    console.log('confirmation');
    Cookies.set('remodal_closed', '1', { expires: 7 });
});

Upvotes: 0

Maciej Kwas
Maciej Kwas

Reputation: 6439

use the event given in documentation and set some cookie, before showing modal to the user check that cookie

$(document).on('closed', '.remodal', function (e) {
    console.log('closed');
    // set cookie here
    console.log(e.reason);
});

Upvotes: 1

Related Questions