[英]Closing popup window after 3 seconds
我需要在 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>
使用 setTimeout,例如:
var win = window.open("http://www.google.com", '1366002941508','width=500,height=200,left=375,top=330');
setTimeout(function () { win.close();}, 3000);
示例小提琴: http : //jsfiddle.net/N5rve/
<script type="text/javascript">
function closeWindow() {
setTimeout(function() {
window.close();
}, 3000);
}
window.onload = closeWindow();
</script>
那应该这样做。
这是一个关于倒计时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>
我在这里找到了它。 希望这对你有所帮助。
尝试
<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;
}
<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;
}
使用本教程来获得你想要的
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>
创建一个全局变量并在我们的代码中重用它。
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); }
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.