Parent Child windows

Discussion in 'JavaScript' started by jecker, Jun 19, 2007.

  1. #1
    I am trying to create a parent child window relationship were the parent window cannot be made active until the child window is closed. Is that possible, if so how can I make this happen?
     
    jecker, Jun 19, 2007 IP
  2. newbish

    newbish Peon

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I have not tested this but and haven't done JS in a while but, you could have the parent window set the focus to the child and set a variable. Then have the parent check the variable on focus, if the value is set re-focus the child. To unset the value of the parent window when the child is completed use the "opener" syntax to refer to the parent.

    Parent
    
    var focusChild = false;
    var theWin;
    function OpenWindow() {
      theWin = window.open(...);
      focusChild = true;
      ...
    }
    
    function CheckVar() {
     if (focusChild)
       theWin.focus();
    }
    
    function FocusParent() {
      focusChild = false;
    }
    
    window.onfocus = CheckVar;
    
    Code (markup):
    Child
    
    
    function UnsetFocus() {
      opener.FocusParent();
    }
    
    window.onunload = UnsetFocus;
    
    Code (markup):
     
    newbish, Jun 19, 2007 IP
  3. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #3
    A web app is not as capable as a desktop app and making one act like that often causes problems with usability. If you must, then how about explaining why you want to do this, there are a few things I am thinking of but I doubt they would be suitable - e.g. covering the parent page rendering it useless, using a layer on top of the page instead of a child window... I doubt you can take restrict focus to the parent, at least in a cross browser compatible manner.
     
    krt, Jun 19, 2007 IP