Javascript Close Popup windows after certain time

2020-05-04 22:31发布

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. Where do I put in the time limit for the popup window and

  2. 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?:

The code

<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">

标签: javascript
1条回答
趁早两清
2楼-- · 2020-05-04 23:06

There is a setInterval function in Javascript, Usage :

$(document).ready(function(){
    if(testwindow  && !testwindow.closed){
        self.setInterval("winClose()",20000);
    }
});
查看更多
登录 后发表回答