javascript 窗口在 15 分钟后关闭

发布于 2024-09-17 19:55:48 字数 461 浏览 1 评论 0原文

现在,我的脚本可以工作,但前提是关闭的时间间隔很短(5 分钟有效),但是当我尝试将超时设置为 15 分钟时,它每次都会失败。我正在使用的脚本是:

function openClose(){
    my_window = window.open('http://www.somesite.com',
    "mywindow","status=1,width=1010,height=740");  //this should execute closepopup() after 15mins if my math is correct
    setTimeout(closepopup,900000); 
    }
    function closepopup(){
        if(false == my_window.closed){
            my_window.close();
        }   
    }

Now, I have script that works, but only if time interval for closing is small (5mins works), but when I try to set timeout to 15mins, it fails every time. The script I'm using is:

function openClose(){
    my_window = window.open('http://www.somesite.com',
    "mywindow","status=1,width=1010,height=740");  //this should execute closepopup() after 15mins if my math is correct
    setTimeout(closepopup,900000); 
    }
    function closepopup(){
        if(false == my_window.closed){
            my_window.close();
        }   
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自找没趣 2024-09-24 19:55:48

只是一个想法 - 垃圾收集器可以处理不需要的变量吗?我可以看到 my_window 是一个全局变量,请尝试保留计时器变量:

timer = setTimeout(closepopup,900000)

请让我知道这是否适合您。

Just a thought - could garbage collector dispose unwanted variables? I can see that my_window is a global one, try to persist timer variable as well:

timer = setTimeout(closepopup,900000)

Please, let me know if this works for you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文