【问题标题】:Closing popup window after 3 seconds3秒后关闭弹出窗口
【发布时间】:2020-12-08 01:58:24
【问题描述】:

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

【问题讨论】:

标签: javascript html


【解决方案1】:

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

【讨论】:

    【解决方案2】:
    <script type="text/javascript">
     function closeWindow() {
        setTimeout(function() {
        window.close();
        }, 3000);
        }
    
        window.onload = closeWindow();
        </script>
    

    应该可以的。

    【讨论】:

    • 它仅在窗口打开后立即调用时有效。看起来它不能异步工作。
    【解决方案3】:

    试试

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

    【讨论】:

    • Arun P Johny:根本没用。这两个代码元素应该分开还是应该以smoe方式组合。完全是新手,所以你必须把它拼出来给我。
    【解决方案4】:
    <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;
    }
    

    【讨论】:

    • @leo_ap 这似乎与another answer 完全相同。
    • 正是我想要的。打开包含任何内容的(弹出)窗口并在 3 秒后关闭它。谢谢@leo_ap
    【解决方案5】:

    使用本教程获得您想要的东西

    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>
    

    【讨论】:

      【解决方案6】:

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

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

      【讨论】:

        【解决方案7】:
        <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>
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2012-07-09
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多