SitePoint Sponsor

User Tag List

Results 1 to 14 of 14

Thread: Closing popups

  1. #1
    SitePoint Member
    Join Date
    Jul 2004
    Location
    MA
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Closing popups

    I have a video that plays in a popup window, and when the user clicks anywhere off the window I'd like the window to close, thereby turning off the video.

    In the popup window's <body> statement I have tried

    onBlur="self.close()" and onBlur="window.close()"

    These both work fine in Netscape, but in I.E. 6.0.2 the popup closes as soon as it opens.

    How do I keep this from happening? Or, is there a way to to look for and close the window's name assigned by the popup command (videosmall) when a user has clicked on either: the popup's parent window or its parent window's parent window? (There are at max 3 windows open at a time.)

    Thanks.

  2. #2
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What code are you using to open the pop-up?
    ::: certified wild guess :::

  3. #3
    SitePoint Member
    Join Date
    Jul 2004
    Location
    MA
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's the function:

    Code:
    function videosmall(url){
      screenWindow = window.open(url, "videosmall", "location=no,toolbar=no,menubar=yes,scrollbars=yes,resizable=yes,width=350,height=270");
    }
    and here's the call:

    Code:
    <a href="session3/video/cooper-excerpt.html" onclick="videosmall('session3/video/cooper-excerpt.html'); return false;">Video Excerpt</a>

  4. #4
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try:
    Code:
    var screenWindow = null;
    
    function videosmall(url)
    {
    	screenWindow = window.open(url, "screenWindow", "location=no,toolbar=no,menubar=yes,scrollbars=yes,resizable=yes,width=350,height=270");
    	if (screenWindow && !screenWindow.closed)
    		screenWindow.focus();
    	return false;
    }
    Code:
    <a href="session3/video/cooper-excerpt.html" onclick="return videosmall(this.href)">Video Excerpt</a>
    Some of that is just cosmetic; the call to focus() is serious. If that doesn't solve it, try doing:
    Code:
    <body onblur="setTimeout('self.close()',100)">
    ...in the pop-up.
    ::: certified wild guess :::

  5. #5
    SitePoint Member
    Join Date
    Jul 2004
    Location
    MA
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your time on this. Neither of these worked in I.E. 6.0.2, though, unfortunately. The popup window still closes as soon as it is opened.

    Is it possible that as soon as a user re-clicks on the open parent window or the parent's parent window that I can have it look for and close the popup?

    Thanks. Here's the rough format of the parent / child:

    http://www2.edc.org/cope/projsupport...mplevideos.htm

  6. #6
    SitePoint Member
    Join Date
    Jul 2004
    Location
    MA
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    P.S. I just got my video popup to close from the parent window using a <body onFocus...> command, but is there a way to also remotely close the popup from the window that launched the parent? I tried searching for the popup's handler like I did from the popup's parent, but the grandparent doesn't recognize it. (Or rather, it ignores the whole command.)

    Thanks.

  7. #7
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'd recommend against getting too involved here with scripting multiple windows. No obvious reason why controlling the behavior of the pop-up itself shouldn't work. Couldn't reproduce the problem locally. Used this:
    Code:
    <script type="text/JavaScript">
    
    var closerID = null;
    onblur = function()
    {
    	closerID = setTimeout('self.close()',100);
    }
    
    </script>
    ...in the screenWindow and had no problems, cross browser. This issue usually arises because something in the pop-up document - usually (but not always) a form element - is grabbing the focus, blurring the window itself, which is quite feasible. The solution is to put clearTimeout(closerID) in the onfocus handler of the object; the 1/10 second delay allows the focusing of the element to cancel the blurring handler of the window. Is that window simply closing immediately, upon opening, without user action? Odd...
    ::: certified wild guess :::

  8. #8
    SitePoint Member
    Join Date
    Jul 2004
    Location
    MA
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by adios
    This issue usually arises because something in the pop-up document - usually (but not always) a form element - is grabbing the focus, blurring the window itself, which is quite feasible.
    You are absolutely right! I discovered that the QuickTime video that loads and plays in the popup is grabbing the focus immediately.

    Quote Originally Posted by adios
    The solution is to put clearTimeout(closerID) in the onfocus handler of the object; the 1/10 second delay allows the focusing of the element to cancel the blurring handler of the window.
    Sorry, can you tell me more about this? Where do I put this, and how do I use it?

  9. #9
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You should be using the <object> tag as well, explained here.

    Before fiddling too much with this, try the following:
    Code:
    <script type="text/JavaScript">
    
    var closerID = null;
    
    onload = function()
    {
    	onblur = function()
    	{
    		closerID = setTimeout('self.close()',100);
    	}
    }
    
    </script>
    Hopefully that'll let the movie grab focus before the handler is registered.
    ::: certified wild guess :::

  10. #10
    SitePoint Member
    Join Date
    Jul 2004
    Location
    MA
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Starting from a clean cache, the code works the first time.

    Before I added the Object properties, the code worked about half the time thereafter. The other times the popup immediately closed upon opening.

    After I added the Object properties, the code worked the first time after emptying my cache but never again.

    I did try decreasing the time to 50 and increasing it to 200, but this didn't make a difference.

    Still works fine in Netscape.

  11. #11
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Get back to you asap...need to set up a demo.
    ::: certified wild guess :::

  12. #12
    SitePoint Member
    Join Date
    Jul 2004
    Location
    MA
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No problem, thanks very much for your help and time so far. I have gone the easy way out: put "Close" links on all the video popups and searched for and closed the popup handler from the parent page. At some point they have to click on the parent page (in whatever format it happens to be), so whether it's immediate or in a couple of minutes the video will eventually stop automatically.

    However, if you have any revelations, I'd still like to know as this will probably come up in some form in the future.

    Here's the URL currently if you're interested and bored of whatever else you're doing.

    You can go directly to the parent page:
    http://www2.edc.org/COPE/projsupport...mplevideos.htm

    Or see the whole shebang: http://www2.edc.org/cope/projsupport/msp_reta/opd_demo/
    After you launch the tour, video is slide ball 13 (they are labeled).

  13. #13
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    After fiddling with this for way too long, I have only one revelation: don't do it. Tested in several browsers, with varying results: the sequence of events firing varies too much to be relied upon. Some QTs pull focus, other's don't, the onload handler runs irregularly - nothing uniform. Tried some different approaches, none very robust. Since 'close on blur' is a nice, but totally unnecessary, feature, I'd ditch it where 'active' content is involved, as the control over focus is iffy.

    Sounds like you've got it running acceptably anyway. Always nice to learn something useful.
    ::: certified wild guess :::

  14. #14
    SitePoint Member
    Join Date
    Jul 2004
    Location
    MA
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Righto. Thanks again.

    Adios, adios!


Bookmarks

Posting Permissions

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