3秒后关闭弹出窗口
我需要在3秒后关闭下面的弹出窗口。我该怎么做。3秒后关闭弹出窗口
<map id="ImgMap0" name="ImgMap0">
<area alt="" coords="127, 22, 20" alt="" title="click here" href="includes/popup1.htm" onclick="javascript:void window.open
('includes/popup1.htm','1366002941508','width=500,height=200,left=375,top=330');return false;" shape="circle" />
</map></p>
<script type="text/javascript">
function closeWindow() {
setTimeout(function() {
window.close();
}, 3000);
}
window.onload = closeWindow();
</script>
应该这样做。
@OP这段代码究竟是什么帮助你? – KodeSeeker 2013-04-21 02:50:23
尝试
<area alt="" coords="127, 22, 20" alt="" title="click here" href="includes/popup1.htm" onclick="openWindow()" shape="circle" />
function openWindow(){
var win = window.open('includes/popup1.htm', '1366002941508', 'width=500,height=200,left=375,top=330');
setTimeout(function(){
win.close()
}, 3000);
return false;
}
Arun P Johny:根本没有工作。如果这两个代码元素是分开的,或者应该以sm way方式进行组合。总新手,所以你将不得不拼出来给我。 – user964377 2013-04-21 02:46:21
是开启窗口 – 2013-04-21 02:51:55
请尝试http://jsfiddle.net/arunpjohny/9e2yM/1/ – 2013-04-21 02:53:33
使用的setTimeout,例如:
var win = window.open("http://www.google.com", '1366002941508','width=500,height=200,left=375,top=330');
setTimeout(function() { win.close();}, 3000);
<script type="text/javascript">
function popup() {
var myPopup = window.open('includes/popup1.htm','1366002941508','width=500,height=200,left=375,top=330');
var t=setTimeout(myPopup.close(),3000);
return false;
}
</script>
<map id="ImgMap0" name="ImgMap0">
<area alt="" coords="127, 22, 20" alt="" title="click here" href="includes/popup1.htm" onclick="popup();" shape="circle" />
</map>
使用本教程来得到你想要的
http://www.tizag.com/javascriptT/javascriptredirect.php
<html>
<head>
<script type="text/javascript">
function close_popup(){
//code here...
}
</script>
</head>
<body onLoad="setTimeout('close_popup()', 3000)"> // 3000 milisec = 3sec
</body>
</html>
<area alt="" coords="127, 22, 20" alt="" title="click here" href="includes/popup1.htm" onclick="openWindow()" shape="circle" />
function openWindow(){
var win = window.open('includes/popup1.htm', '1366002941508', 'width=500,height=200,left=375,top=330');
setTimeout(function(){
win.close()
}, 3000);
return false;
}
哈桑你好,请考虑解释你的代码 – 2017-02-09 17:31:38
@leo_ap这似乎是一个完全重复[另一个答案](https://stackoverflow.com/a/16127137/421245)。 – 2017-08-04 18:22:25
这是JavaScript的自动弹出闭合的3秒钟,之后倒计时一个例子,
<p style="text-align:center">This window will close automatically within <span id="counter">3</span> second(s).</p>
<script type="text/javascript">
function countdown() {
var i = document.getElementById('counter');
i.innerHTML = parseInt(i.innerHTML)-1;
if (parseInt(i.innerHTML)<=0) {
window.close();
}
}
setInterval(function(){ countdown(); },1000);
</script>
我发现它here。希望这会对你有所帮助。
使用['setTimeout'](https://developer.mozilla.org/en-US/docs/DOM/window.setTimeout)。 – Dom 2013-04-21 01:41:16
[如何自动关闭网页]可能的重复(http://stackoverflow.com/questions/14621554/how-to-close-automatically-a-webpage) – davidcondrey 2016-03-02 02:09:52