场景是:每小时用户都会看到一个弹出窗口(javascript/jQuery)。如果用户不响应弹出窗口, session 就会被破坏。现在我面临一个问题,如果弹出窗口没有得到答复,如何触发函数。请帮忙。到目前为止我的代码如下。
function popitup() {
newwindow=window.open('/Untitled-3.html','name','height=500,width=500');
if (window.focus) {newwindow.focus()}
return false;
}
//popitup();
function showpop(){
var x;
var r=confirm("Press a button!");
if (r==true)
{
x="You pressed OK!";
}
else
{
x="You pressed Cancel!";
closeWin();
}
setTimeout(closeWin,15000);
}
function closeWin()
{
newwindow.close();
}
setInterval ( showpop, 10000 );
最佳答案
相反setInterval
尝试setTimeOut(closeWin, 10000);
这将在 10 秒后调用 closeWin 函数。
您也可以尝试这样的方法:
res = inform("您在此留言"); if(res==true) {window.location="abc.html"}
setTimeout(function(){window.location="abc.html"},10000);
关于javascript - 如果弹出窗口未得到答复,则调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21402725/