Html 3 秒后关闭弹出窗口
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16127115/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Closing popup window after 3 seconds
提问by user964377
I need to close the popup windows in the following after 3 seconds. How do I do it.
我需要在 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>
回答by John Koerner
Use a setTimeout, for example:
使用 setTimeout,例如:
var win = window.open("http://www.google.com", '1366002941508','width=500,height=200,left=375,top=330');
setTimeout(function () { win.close();}, 3000);
Sample fiddle: http://jsfiddle.net/N5rve/
示例小提琴:http: //jsfiddle.net/N5rve/
回答by seeker
<script type="text/javascript">
function closeWindow() {
setTimeout(function() {
window.close();
}, 3000);
}
window.onload = closeWindow();
</script>
That should do it.
那应该这样做。
回答by Sajjad Hossain
This is an example of JavaScript automatic popup closing after 3 seconds with countdown,
这是 3 秒倒计时后 JavaScript 自动弹出关闭的示例,
<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>
I have found it here. Hope this will be helpful for you.
回答by Arun P Johny
Try
尝试
<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;
}
回答by Hasan Rony
<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;
}
回答by satya prakash
Creating a global variable and reuse it in our code.
创建一个全局变量并在我们的代码中重用它。
var info = function (text, onClose, headerText) {
if (!headerText)
headerText = "Info";
alert(text, null, onClose, headerText, true);
}
// Call this in own code where ever you need
info("Message that going to close automatic.");
hidePopUpMessage();
// callback function to showing 3 sec.
function hidePopUpMessage() {
setTimeout(function () {
$("#pp-alert-close").click();
//$("#popup-close").click();
}, 3000);
}
回答by Wayne Tun
use this tutorials to get what you want
使用本教程来获得你想要的
http://www.tizag.com/javascriptT/javascriptredirect.php
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>
回答by Silvertiger
<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>