11

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

7 回答 7

16

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

于 2013-04-21T01:44:08.217 回答
14
<script type="text/javascript">
 function closeWindow() {
    setTimeout(function() {
    window.close();
    }, 3000);
    }

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

那应该这样做。

于 2013-04-21T01:42:08.783 回答
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;
}
于 2013-04-21T01:42:31.740 回答
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;
}
于 2017-02-09T17:22:09.260 回答
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>
于 2013-04-21T01:53:58.607 回答
0

创建一个全局变量并在我们的代码中重用它。

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);
        }

于 2019-06-03T12:52:39.113 回答
-4
<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>
于 2013-04-21T01:46:13.877 回答