Javascript在一段时间后关闭弹出窗口 [英] Javascript Close Popup windows after certain time

查看:61
本文介绍了Javascript在一段时间后关闭弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我不知道JavaScript。所以我的主页上有一个弹出窗口,给客户带来圣诞祝福。我希望弹出窗口在20秒后关闭。我从互联网上获得了以下代码,弹出窗口打开正常但我需要以下帮助:

Hi first of all I don't know JavaScript. So I've got a popup window on my main page with Christmas wishes for the clients. I want the popup windows to close after say 20 seconds. I got the following code from the internet, the popup window opens fine but I need help with the following:


  1. 我在哪里放入弹出窗口的时间限制和

  1. Where do I put in the time limit for the popup window and

我在哪里告诉页面运行关闭弹出窗口的功能,我有功能winClose但我必须把它放在标签中吗?:

Where do I tell the page to run the function to close the popup window, I've got the funcion winClose but must I also put that in the tag?:

代码

<script type="text/javascript">
function poponload()
{
    testwindow = window.open("cm.html", "myWindow", "location=1,status=1,scrollbars=1,width=600,height=500");
}
function winClose() {
     myWindow.close()
}   
</script>
</head>
<body onload="javascript: poponload()" bgcolor="#FFFFFF" text="#000000" topmargin="0">


推荐答案

有一个 setInterval 功能 Javascript ,用法:

$(document).ready(function(){
    if(testwindow  && !testwindow.closed){
        self.setInterval("winClose()",20000);
    }
});

这篇关于Javascript在一段时间后关闭弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆