Reputation: 820
i have a jquery dialog
which is open on every page load. jquery dialog
contain a close button.
$(document).ready(function () {
$("#dialog").dialog({
title: "Create your free showcase profile",
autoOpen: true,
hide: 'fold',
show: 'blind',
width: 'auto',
modal: true,
buttons: {
Close: function () {
$(this).dialog('close');
}
}
});
setInterval(function () {
$('#dialog').dialog('open');
}, 10000);
});
Now what i am trying to do is , when the dialog was closed by the user by clicking the Close
button , it would not visible again to user till the end of session.
please help to achieve this
Upvotes: 0
Views: 402
Reputation: 18873
You can set a localStorage
and store a token value in it and then check localstorage
as shown:
$(document).ready(function () {
var $dialog = $("div").dialog({
title: "Create your free showcase profile",
autoOpen: false,
hide: 'fold',
show: 'blind',
width: 'auto',
modal: true,
buttons: {
Close: function () {
localStorage.setItem('token','closed');
$(this).dialog('close');
}
}
}).dialog('open'); //trigger on page load
var init = setInterval(function () {
if(localStorage.getItem('token') == 'closed')
{
clearInterval(init);
return;
}
$dialog.dialog('open');
}, 10000);
});
OR use sessionStorage
as shown :
$(document).ready(function () {
var $dialog = $("div").dialog({
title: "Create your free showcase profile",
autoOpen: false,
hide: 'fold',
show: 'blind',
width: 'auto',
modal: true,
buttons: {
Close: function () {
sessionStorage.setItem('token','closed');
$(this).dialog('close');
}
}
}).dialog('open'); //trigger on page load
var init = setInterval(function () {
if(sessionStorage.getItem('token') == 'closed')
{
clearInterval(init);
return;
}
$dialog.dialog('open');
}, 10000);
});
Upvotes: 1