Closing popup window after 3 seconds

前端 未结 8 1476
孤独总比滥情好
孤独总比滥情好 2020-12-03 18:02

I need to close the popup windows in the following after 3 seconds. How do I do it.


                  

        
相关标签:
8条回答
  • 2020-12-03 18:26

    use this tutorials to get what you want

    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>
    
    0 讨论(0)
  • 2020-12-03 18:27

    Use a setTimeout, for example:

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

    Sample fiddle: http://jsfiddle.net/N5rve/

    0 讨论(0)
  • 2020-12-03 18:32
    <script type="text/javascript">
     function closeWindow() {
        setTimeout(function() {
        window.close();
        }, 3000);
        }
    
        window.onload = closeWindow();
        </script>
    

    That should do it.

    0 讨论(0)
  • 2020-12-03 18:32
    <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 讨论(0)
  • 2020-12-03 18:35

    This is an example of JavaScript automatic popup closing after 3 seconds with countdown,

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

    I have found it here. Hope this will be helpful for you.

    0 讨论(0)
  • 2020-12-03 18:35

    Creating a global variable and reuse it in our code.

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

    0 讨论(0)
提交回复
热议问题