Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Posts
    553
    Thanks
    0
    Thanked 0 Times in 0 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?

    G

    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)">');
    playPop.document.close();
    Last edited by gorilla1; 07-09-2002 at 05:14 AM.

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    lol....because you have this here: 'self.close()::::it will close the parent

    replace it with
    playPop.document.close();

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Posts
    553
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Alien51,

    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.

    G

  • #4
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    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:

    onload="opener.closeFunction()"

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

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    try:

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

    setTimeout("playPop.close()",5000);


    If you don't hear the music play, try to make the delay longer.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #6
    Regular Coder
    Join Date
    Jun 2002
    Posts
    553
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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.

    G

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

    playPop.document.write('<Body>');

    playPop.document.close();
    Last edited by gorilla1; 07-09-2002 at 02:13 PM.

  • #7
    Regular Coder
    Join Date
    Jun 2002
    Posts
    553
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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.

    G

    <HTML>
    <head>
    </head>
    <Body>
    <EMBED src="mussati.mid" autostart="true" loop="true" hidden="true">

    </BODY></HTML>

  • #8
    New Coder
    Join Date
    Jul 2002
    Location
    USA, East Coast
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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
    Senior Coder
    Join Date
    Jun 2002
    Posts
    1,404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    Try this:

    Code:
    <html>
    <head>
    <title>untitled</title>
    <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);
    playPop.blur();
    }
    
    </script>
    </head>
    <body>
    <a href="javascript&#58;void openplayPop()">MUSIC</a>
    </body>
    </html>

  • #10
    Regular Coder
    Join Date
    Jun 2002
    Posts
    553
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

    G.
    Last edited by gorilla1; 07-09-2002 at 10:00 PM.

  • #11
    Regular Coder
    Join Date
    Jul 2002
    Location
    U.S. (Wish Japan though)
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •