Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Giving Parent Window Focus after Modal Closes

I execute a block of code when a particular window gets focus like this:

myWindow.addEventListener('focus', function(){
   //Totally Rad Code...

I also fire a modal from this page, and when the user hits "Okay" to close that modal, it takes them back to the parent window (myWindow). But it doesn't give that window focus and thus doesn't execute my code above.

I can't just say myWindow.focus(); from within the modal, because it's out of context. I tried making the code block above a regular function inside a global include, but all the variables inside it are out of scope unless executed from inside myWindow.

Anyone have any ideas on what I can do to trigger focus for myWindow from within a modal as it closes?

— asked August 5th 2010 by Clifton Labrum
  • focus
  • modal
  • parent
  • window

1 Answer

  • Accepted Answer

    It seems that the event focus never gets called if you use a Modal Window.
    I tried but can't get any code to execute using this method.

    In the end, I used another event which achieve the same results.
    I usedthe Modal Window çlosed event

    So, you have:

    myWindow.addEventListener('focus', function(){
    //Totally Rad Code…

    //// Above never gets called when Model Window close

    ModalWindow.addEventListener('close', function(){
    //Totally Rad Code…

    /// Gets called when Modal Window closes.

    Test it!

    — answered August 5th 2010 by Peter Lum
    1 Comment
    • Works perfectly, thank you!

      — commented August 5th 2010 by Clifton Labrum
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.