when the site opens, I open a modal . When the site is closed, I want to delete the cookies. I tried the codes below, but when the page is refreshed, the modal opens again. How can I delete cookies only when the site is closed. thanks
$(document).ready(function () {
if ($.cookie("announcement") == null) {
$.cookie("announcement", "yes");
$("#large").modal("show");
}
});
function cookieDelete() {
$.removeCookie("announcement");
}
$(window).on("beforeunload", function () {
cookieDelete();
return;
});
2
Answers
You have to delete the cookie on .unload event
If Cookie is not a requirement, I suggest an alternate solution using Session Storage
You don’t need to handle
delete
operation becausesession storage
will be cleared automatically when the page is closed.