調查jQuery UI's modal和sessionStorage。
以下是你可能會找什麼一個例子:
function showHelpModal()
{
// Open the dialog and reset the timer
$('#mymodal').dialog('open');
timeoutStarted = false;
}
var t; // Timeout variable
var timeout = 1500; // Timeout in milliseconds
var fakeSessionStorage = {}; // The fake sessionStorage, don't use this in your real code
$(document).ready(function()
{
// Initialize the dialog
$('#mymodal').dialog(
{
autoOpen: false,
height: 500,
width: 500,
modal: true,
buttons: {
"Don't remind me": function()
{
fakeSessionStorage.stopReminding = true;
$(this).dialog('close');
},
"Yes, please": function()
{
$(this).dialog('close');
}
}
});
// Set default reminder value
if(!fakeSessionStorage.stopReminding)
fakeSessionStorage.stopReminding = false;
// On scroll...
$(document).scroll(function()
{
// If the user doesn't want to be reminded, return false
if(fakeSessionStorage.stopReminding)
{
console.log("Will not remind again");
return false;
}
// Start the timer and prevent it from firing while busy
timeoutStarted = true;
clearTimeout(t);
t = setTimeout(showHelpModal, timeout);
});
});
而在JSfiddle
工作的例子請介意你的sessionStorage不上的jsfiddle工作,所以我用了一個對象調用fakeSessionStorage
來掩飾這一點。
另外,sessionStorage在Internet Explorer 7或更低版本中不起作用。
我錯了小提琴鏈接,修正了這一點。
[編輯2]
具有timeoutStarted
變量有明顯的問題。我認爲這是一件必要的事情,但它做得比壞好多了。
看看jQuery的UI。另外,你已經嘗試過什麼? – MisterBla
我相信你錯誤標記了PHP,這裏沒有任何關聯。 –
@DarylGill會話是PHP。但他可以使用cookie或sessionStorage。 – MisterBla