[英]How to display a popup message after a delay
我想在用戶訪問我的網站時顯示彈出消息,並在3小時后顯示下一個彈出窗口。
我已經完成了一半,因為我實現了第一次訪問時顯示的彈出消息。
請指導我將彈出窗口延遲3小時后如何顯示?
謝謝。
如果您使用的是JavaScript,則可以通過以下方式使用本地存儲:
$(document).ready(function() {
var visited = localStorage['visited'];
if (!visited) {
localStorage['visited'] = Math.round(+new Date()/1000)
//Run initial pop up code
}
window.setInterval(function(){
visited = localStorage['visited'];
if(visited != "finished") {
if (visited + (3600*3) < Math.round(+new Date()/1000)) {
//Run popup code for after 3 hours
localStorage['visited'] = "finished";
}
}
}, 60000);
});
正如其他人已經建議的那樣,setInterval可能正是您想要的。 有關示例,請參見此jsFiddle: http : //jsfiddle.net/dswknovp/祝您好運!
HTML:
<span id="alertText"></span>
JS:
var myTimer = 1000*3; // every 3 seconds for testing, use: 1000*60*60*3; //for 3 hours
var myStart = setInterval(function(){
myAlarm()
}, myTimer);
function myAlarm() {
document.getElementById("alertText").innerHTML += "-Time elapsed-";
//you can change this to, for example: alert("Time is up");
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.