Titanium Community Questions & Answer Archive

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

Close Window and Return to Home?

I've got a webview in a current window that I want to close and return to my apps.js "home" page but I cannot get it to work. Apps.js is in a parent (root) directory from where I currently am. Here's the code I'm currently working with. MUCH THANKS!

var win = Titanium.UI.currentWindow;

var webview = Titanium.UI.createWebView({url:'http://www.foo.com/About.html'});



var win = Titanium.UI.createWindow({title: 

'About', barColor: '#4b4b4b'});
win.add(webview);
win.open({modal:true});

var close = Titanium.UI.createButton({
    title:'close',
    width:200,
    height:40,
    top:60
});
win.add(close);
close.addEventListener('click', function()
{
    win.close();
});
win.open({url:'apps.js'});
— asked April 1st 2010 by Mark Smillie
  • navigation
0 Comments

4 Answers

  • close.addEventListener('click', function()
    {
    win.close();
    });
    win.open({url:'apps.js'});

    Change to…
    close.addEventListener('click', function()
    {
    win.remove(webview);
    });

    — answered April 1st 2010 by Eldon Benz
    permalink
    0 Comments
  • Eldon…thanks for the quick reply…however…it throws me out of the app…

    2010-04-01 10:47:27.872 Player[4956:207] Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: ' -[TiUIWindowProxy removeFromSuperview]: unrecognized selector sent to instance 0x9502f00'
    2010-04-01 10:47:27.872 Player[4956:207] Stack: (…

    — answered April 1st 2010 by Mark Smillie
    permalink
    0 Comments
  • Mark

    You must not be using the latest 1.1.2

    Remove did cause a crash in older versions

    — answered April 1st 2010 by Eldon Benz
    permalink
    0 Comments
  • I don't think you should try to open different windows from one window object simultaneously.

    Try this:

    var win = Titanium.UI.createWindow({
        title:'About',
        barColor: '#4b4b4b'
    });
    
    var webview = Titanium.UI.createWebView({
        url:'http://www.foo.com/About.html'
    });
    win.add(webview);
    
    var close = Titanium.UI.createButton({
        title:'close',
        width:200,
        height:40,
        top:60
    });
    win.add(close);
    
    close.addEventListener('click', function()
    {
        win.close();
    });
    
    win.open({modal:true});
    
    // Why do you need to open this next window?
    // If it's meant to appear 'below' the modal window,
    // consider opening this window first.
    
    var win2 = Ti.UI.createWindow({url:'../apps.js'});
    win2.open;
    

    (I assume you're not using tabs - that would require Ti.UI.currentTab.open(win2).)

    — answered April 2nd 2010 by James K
    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.