Titanium Community Questions & Answer Archive

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

Closing multiple windows

Hi

On iPhone, I am creating windows in same tab like this

win1 -> win2 -> win3 -> win4

Now I want to call an event from a different tab which should be able to close win4 till win2 leaving only win1 open.

I tried the approach of attaching an event listener in all windows to close them and then called it in it's child's close event, but this leaves me on win2 with no background and navbar showing it's title.

Please help me out in achieving it.

— asked April 4th 2010 by Dev Priya
  • iphone
  • window
1 Comment
  • What about adding the event listener in each window where the window will call the previous event listener right before it closes?

    // In some utilities js
    function close_window_chain(new_win, old_win, e) {
      // Trigger closing of old win
      old_win.dispatchEvent('close_win_chain');
      // Close this window
      new_win.close();
    }
    
    // In each window from now to future...
    include('utilites.js');
    
    var old_win = Titanium.UI.currentWindow();
    var new_win = Titanium.UI.createWindow({});
    new_win.addEventListener('close_win_chain', function(e){
      close_window_chain(new_win, old_win, e);
    });
    
    // ... in some window in the future
    Titanium.UI.currentWindow.dispatchEvent('close_win_chain');
    

    Haven't tested this…

    — commented September 9th 2011 by Ryan Schumacher

3 Answers

  • I would also like to know how to accomplish this. I guess we need to keep track of win2, win3, etc, but I'm not sure how to do this from window to window. Any help would be appreciated.

    — answered August 13th 2010 by Mark Ross
    permalink
    0 Comments
  • Hi,

    try this

    /*
     * At win1 during win2 creation
     */
    var win1 = Ti.UI.currentWindow;
    var win2 = Ti.UI.createWin...
    {
      //all win props,
      url:'win2.js',     
    }
    
    /*
     * At win2 during win3 creation
     */
    var win2 = Ti.UI.currentWindow;
    var win3 = Ti.UI.createWin...
    {
      //all win props,
      url:'win3.js',
      _win2:win2, // we add win2 to win3    
    }
    
    /*
     * At win3 during win4 creation
     */
    var win3 = Ti.UI.currentWindow;
    var win4 = Ti.UI.createWin...
    {
      //all win props,
      url:'win4.js',
      _win3:win3, // we add win3 to win4
      _win2:win3._win2, // we add win2 to win4    
    }
    
    /*
     * On win4 
     */
    var win4 = Ti.UI.currentWindow;
    //add an event on win4
    Ti.pp.addEventListener('closeAllWin',function({
     //we start closing the windows from win2 to win4 and if you try the other way round 
     //this wont work
      win4._win2.close();
      win4._win3.close();
      win4.close();     
    }));
    
    — answered September 9th 2011 by Satta Ravi
    permalink
    0 Comments
  • Have similar problem; win1 > win2 w/o tabs and want to add event listener in win2 but it doesn't respond ? How does "_win2:win2" work ?

    — answered September 13th 2011 by John Mohan
    permalink
    0 Comments
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.