Web Analytics Made Easy -
StatCounter About pop up generator - CodingForum

Announcement

Collapse
No announcement yet.

About pop up generator

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • About pop up generator

    Hello all. i would like to ask something
    Is there a way to make the pop up window auto close after x seconds?
    Code:
    //JK Popup Window Script (version 3.0)- By JavaScript Kit (http://www.javascriptkit.com)
    //Visit JavaScriptKit.com for free JavaScripts
    //This notice must stay intact for legal use
    //Win Type: Pop Up | Session Only
        
    //Specify URLs to randomly select from and popup/popunder:
    //To display a single URL, just remove all but the first entry below:
    var popurls=new Array()
    popurls[0]=""
    
    function openpopup(popurl){
    var winpops=window.open(popurl,"","width=400,height=400,status,scrollbars,resizable")
    }
    
    function get_cookie(Name) {
      var search = Name + "="
      var returnvalue = "";
      if (document.cookie.length > 0) {
        offset = document.cookie.indexOf(search)
        if (offset != -1) { // if cookie exists
          offset += search.length
          // set index of beginning of value
          end = document.cookie.indexOf(";", offset);
          // set index of end of cookie value
          if (end == -1)
             end = document.cookie.length;
          returnvalue=unescape(document.cookie.substring(offset, end))
          }
       }
      return returnvalue;
    }
    
    function loadornot(){
    if (get_cookie('jkpopup')==''){
    openpopup(popurls[Math.floor(Math.random()*(popurls.length))])
    document.cookie="jkpopup=yes"
    }
    }
    
    loadornot()
    </script>
    Is there something i can add here to make it auto close?

    Thanks in advance

  • #2
    That's probably the wrong place to add that functionality. But you could (if you have no control over the popupped content), add it to the opened window and load the content in a frame.
    .My new Javascript tutorial site: http://reallifejs.com/
    .Latest article: Calculators — Tiny jQuery calculator, Full-fledged OOP calculator, Big number calculator
    .Latest quick-bit: Including jQuery — Environment-aware minification and CDNs with local fallback

    Comment


    • #3
      Change this:-

      Code:
      function openpopup(popurl){
      var winpops=window.open(popurl,"","width=400,height=400,status,scrollbars,resizable")
      }
      to this:-

      Code:
      var winpops="";
      function openpopup(popurl) {
      if (winpops != "") {winpops.close()}
      winpops=window.open(popurl,"","width=400,height=400,status,scrollbars,resizable");
      window.setTimeout("closepop()",5000);  // 5 seconds delay
      }
      
      function closepop(){
      winpops.close();
      }

      BTW, the time to say "thanks" is afterwards, not beforehand which gives the impression that you take other people's voluntary unpaid assistance for granted. Or as British politician Neil Kinnock put it, "Don't belch before you have had the meal." Prefer to use "please" beforehand and if you find a response helpful then you can use the "Thank User For This Post" button.

      All the code given in this post has been tested and is intended to address the question asked.
      Unless stated otherwise it is not just a demonstration.

      Comment


      • #4
        Ummmm....there's a bug in that.

        If a second call is made to openpopup( ), then you will get an error on the first line, when trying to do winpops.close, because winpops will no longer be equal to "".

        Code:
        var winpops="";
        function openpopup(popurl) {
            if (winpops != "") {winpops.close()}
            winpops  = window.open(popurl, "[B]_blank[/B]", "width=400,height=400,status,scrollbars,resizable");
            window.setTimeout("closepop()",5000);  // 5 seconds delay
        }
        
        function closepop()
        {
            [B]if ( winpops != "" ) [/B]winpops.close();
            [B][COLOR="Red"]winpops = "";[/COLOR][/B]
        }
        
        .
        It's not a big deal, but it's better to use the window name "_blank" if you want to ensure a new window. Or you can use somenthing like "POPUP" so all your popups open in the same window.
        Be yourself. No one else is as qualified.

        Comment


        • #5
          first link in google for timed pop ups
          http://www.codelifter.com/main/tips/question041.shtml


          I made this long a time ago and saw it the other day, so I just uploaded the scripts to laugh about!
          http://h1.ripway.com/stirfry/javascr...opups/new.html
          Enjoy

          many popups,,,beware.
          it pops 4 windows in the corners each 25% of the screenand the close after a few seconds and their content is done playing.
          Included sounds too! hahah
          the page was made as a joke, so please don't use it. LOL
          Last edited by TinyScript; Apr 16, 2009, 05:08 AM.

          Comment

          Working...
          X