When the visitor closes the window, either by want of disregarding the message or after subscribing to the newsletter, it's important to ensure the window doesn't again appear following the next request (even a page reload request). To prevent subsequent modal windows from appearing for a designated period of time, we'll set a cookie after closing the window and then check whether that cookie exists with each request. The
jquery-cookie plugin makes this a trivial matter. Begin by downloading the plugin and then referencing it within your website like this:
$(document).ready(function () {
if ($.cookie("newsletter") != 1) {
$('#basic-modal-content').modal({
onClose: function() {
$.cookie("newsletter", "1", { expires: 7 });
$.modal.close();
}
});
}
});
As a reminder, be sure to set the cookie expiration date far enough into the future so the visitor will not become annoyed by the modal dialog. Additionally, when using modal dialogs for features such as a newsletter subscription prompt, consider setting a different cookie following the window's closure which sets a cookie which never expires, just to make sure the user doesn't attempt to again subscribe to the newsletter.