2013-04-21 57 views
5

Tôi cần đóng cửa sổ bật lên sau đây trong 3 giây. Tôi phải làm nó như thế nào.Đóng cửa sổ bật lên sau 3 giây

<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

Sử dụng ['setTimeout'] (https://developer.mozilla.org/en-US/docs/DOM/window.setTimeout). – Dom

+0

Bản sao có thể có của [Cách tự động đóng trang web] (http://stackoverflow.com/questions/14621554/how-to-close-automatically-a-webpage) – davidcondrey

Trả lời

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

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

Điều đó sẽ làm điều đó.

+0

@OP chính xác từ đoạn mã này đã không giúp gì cho bạn? – KodeSeeker

1

Hãy thử

<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: Không làm việc gì cả. Nếu 2 yếu tố mã được tách biệt hoặc nên được kết hợp theo cách smoe. Tổng số newbie, do đó bạn sẽ phải đánh vần nó với tôi. – user964377

+0

là cửa sổ đang mở –

+0

Hãy thử http://jsfiddle.net/arunpjohny/9e2yM/1/ –

11

Sử dụng setTimeout, ví dụ:

var win = window.open("http://www.google.com", '1366002941508','width=500,height=200,left=375,top=330'); 

setTimeout(function() { win.close();}, 3000); 

mẫu fiddle: 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

sử dụng hướng dẫn này để có được những gì bạn muốn

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

Xin chào Hasan, vui lòng xem xét giải thích mã của bạn –

+0

@leo_ap dường như là một trùng lặp chính xác của [câu trả lời khác] (https://stackoverflow.com/a/16127137/421245). –

1

Đây là một ví dụ về Javascript đóng cửa sổ popup tự động sau 3 giây với đếm ngược,

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

tôi đã tìm thấy nó here. Hy vọng điều này sẽ hữu ích cho bạn.

Các vấn đề liên quan