Web Analytics Made Easy -
StatCounter Self closing popup - CodingForum


No announcement yet.

Self closing popup

  • Filter
  • Time
  • Show
Clear All
new posts

  • Self closing popup

    I am trying to open a popup that will play a bit of music, and then I want the popup to close itself after a few seconds. The popup worked fine, until I added the code that would shut the popup, using body unload settimer, as shown below. I don't want to close from the parent page, since the viewer may have moved onto another page. As coded below, the music player (midi file) starts to load, but then disappears, seemingly on the write of the body onload, leaving a blank and quiet popup (coded without the body onload settimer the popup displayed a console and played the music). The popup does close after the 5 seconds, as intended - it's just that the console doesn't stick and so the music never plays. What am I doing wrong?


    playPop = window.open (tuneURL, "toolbar=no,location=0,directories=no,status=no,scrollbars=no,resizeable=no,copyhistory=no,width=200 ,height=30");

    playPop.document.write('<Body onLoad="setTimeout(\'self.close()\',5000)">');
    Last edited by gorilla1; Jul 9, 2002, 12:14 AM.

  • #2
    lol....because you have this here: 'self.close()::::it will close the parent

    replace it with
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]


    • #3

      Maybe I was not clear. The self.close is written to the body tag of the popup. So the popup does close after 5 seconds, as desired (the parent stays open, also as desired). The issue is that the music file no longer plays, now that I am writing something to the window in which it loads... As far as the line of code you suggest, notice that it is already there in my code - see the last line.



      • #4
        Try writing a function in your parent window containing the setTimeout to close the child window

        setTimeout(playpop.close(), 5000)

        and then in the onload of your child window activate the function like so:


        my syntax is a little rusty but you get the idea.
        CodingForum Supreme Overlord
        All Hail Spookster


        • #5

          playPop = window.open (tuneURL, " toolbar=no,location=0,directories=no,status=no,scr


          If you don't hear the music play, try to make the delay longer.
          vBulletin Mods That Rock!


          • #6
            closing popup/loading music file in popup

            Thanks, Spookster, I was able to get that function to run, but still same result. Glenngv, thanks, I had tried that approach, too - it closes the popup from the parent, but will fail to get the job done if the viewer has moved on to another page within the site, leaving the potential for an extraneous window (the music popup) left open after the viewer leaves the site - that is what I am trying to avoid...

            After some more trial and error, I realize I may have complicated the statement of the problem. I took the timer out completely, and had the popup open, and did nothing more with my document.write than add a body tag - and that alone prevents the console from staying and the music playing - the popup opens, the console appears briefly, but then disappears, and the popup just sits there empty.. So the question really is whether it is possible to open a popup this way with a path to a song and have it still play if there is anything else in the document for that popup page (like a body tag). Once I get over that hurdle, than I can the timer back in... The code is shown below. Just adding those 2 document.write statements causes the music file not to play.


            playPop = window.open (tuneURL, " toolbar=no,location=0,directories=no,status=no,scr


            Last edited by gorilla1; Jul 9, 2002, 09:13 AM.


            • #7
              self closing popup/music file

              Well, I can think of a much simpler way to do this. Have the popup be an html file that contains an embed of the music file and have the timeout set in the body onload. Got this to work in IE. However, NS seems to ignore the embed. Now I know NS can handle it, as I have the very same embed code it working under NS4 in another html file from a ways back. So why does NS not play the music, as coded below?
              I feel like I'm cursed.


              <EMBED src="mussati.mid" autostart="true" loop="true" hidden="true">



              • #8
                try this?

                Opening, then writing to a popup window will overwrite the content.

                Add all the content from the original HTML file into the document.write(); including the EMBED tag.

                You mentioned that the EMBED loaded originally? and then stopped? This should be because you just overwrit the entire document with that one statement.

                <Body onLoad="setTimeout(\'self.close()\',5000)">

                so you lost all the other html in the process. (this is what I believe you are doing).

                If you start with <html> and end with </html> and include ALL the necessary html inbetween with the document.write(); I dont see why it shouldnt work.


                If the onload etc. is interferring with the embed tag you can always try using the old redirect method.

                <meta http-equiv="refresh" content="20; URL=autoclose_me.html">

                and have a page autoclose_me.html with only a <script> window.close(); </script> in it.

                -S. Bob


                • #9
                  Try this:

                  <script type="text/javascript" language="JavaScript">
                  var playPop = null;
                  var playSRC = '........../mussati.mid'; //absolute URL
                  var popWid = 200; //minimum 100
                  var popHt = 100; //minimum 100
                  var popBG = 'black';
                  var delay = 5; //close in seconds
                  var HTML = '<html><head><script>onload=function(){';
                  HTML += 'setTimeout("self.close()",' + delay * 1000 + ')}</' + 'script>';
                  HTML += '</head><body bgcolor="' + popBG + '"><embed src="' + playSRC + '" ';
                  HTML += 'autostart="true" loop="true" hidden="true"></embed></body></html>';
                  function openplayPop() {
                  playPop = open ('javascript&#58;opener.HTML','','width=' + popWid + ',height=' + popHt);
                  <a href="javascript&#58;void openplayPop()">MUSIC</a>


                  • #10
                    S. Bob, yes, I think you are right, and I got it going using that approach.

                    Adios, that code is right on the money (though when I run it, it gives a message about the data the plugin requested did not download successfully, which sounds like I fed it the wrong url - I will have to look more). But this is a very nice piece of code, and a nice way to play some music unobtrusively (you can be sure the popup flushes when the music is done, etc.), if the viewer so elects.

                    I worked on this quite a bit, and then tried it on my portable, and while the midi file sounded just passable on my desktop with nice speakers, it was an abominaton on the laptop :-(

                    Thanks all for the generous assistance.

                    Last edited by gorilla1; Jul 9, 2002, 05:00 PM.


                    • #11
                      Since were on the bubject of auto-reload/close, Supr Bob, in the metatag:

                      <meta http-equiv="refresh" content="20; URL=autoclose_me.html">

                      Is the 20 that is inside the content the time limit?

                      Also, does the tag HAVE to be within the head, or can it be writen in the body?

                      I am asking, because I have a random music pop-up, and instead of it constantly repeating the music when the page loads, I want it to refresh for another random song after the current one finishes...

                      Thanks in advance for your help