2013-04-21 112 views
5

我需要在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> 
+1

使用['setTimeout'](https://developer.mozilla.org/en-US/docs/DOM/window.setTimeout)。 – Dom 2013-04-21 01:41:16

+0

[如何自動關閉網頁]可能的重複(http://stackoverflow.com/questions/14621554/how-to-close-automatically-a-webpage) – davidcondrey 2016-03-02 02:09:52

回答

6
<script type="text/javascript"> 
function closeWindow() { 
    setTimeout(function() { 
    window.close(); 
    }, 3000); 
    } 

    window.onload = closeWindow(); 
    </script> 

應該這樣做。

+0

@OP這段代碼究竟是什麼幫助你? – KodeSeeker 2013-04-21 02:50:23

1

嘗試

<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; 
} 
+0

Arun P Johny:根本沒有工作。如果這兩個代碼元素是分開的,或者應該以sm way方式進行組合。總新手,所以你將不得不拼出來給我。 – user964377 2013-04-21 02:46:21

+0

是開啓窗口 – 2013-04-21 02:51:55

+0

請嘗試http://jsfiddle.net/arunpjohny/9e2yM/1/ – 2013-04-21 02:53:33

11

使用的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/

-3
<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> 
0

使用本教程來得到你想要的

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> 
-2
<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; 
} 
+1

哈桑你好,請考慮解釋你的代碼 – 2017-02-09 17:31:38

+0

@leo_ap這似乎是一個完全重複[另一個答案](https://stackoverflow.com/a/16127137/421245)。 – 2017-08-04 18:22:25

1

這是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。希望這會對你有所幫助。

相關問題