Titanium Community Questions & Answer Archive

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

Override Back Button Event on Tab Window

I'm trying to change the back button on a window on a tab.

Currently, the back button goes back to the main window on the tab.

I'd like to change the event to swap out a view… showTableView() or showWebView().

I'm trying to optimize my code to only use a few windows and one web view… similar to Kevin's Snapost example.

// subwindow.js
var win = Titanium.UI.currentWindow;
// Titanium.UI.currentWindow.backgroundColor = 'black';
// Titanium.UI.currentWindow.barColor = 'black';
// Titanium.UI.currentWindow.backgroundImage = '../images/bg.png';
// create view container (allows us to do nice transitions)
var viewContainer = Titanium.UI.createView();
// add main content views to container
// intialize
webView.visible = false;
// modify view visibility for navigation
function showWebView(rowData) {
 alert( rowData.url );
 webView.url = rowData.url;
 win.title = rowData.title;
 tableView.visible = false;
 webView.visible = true;
function showTableView() {
 win.title = 'Best Practices';
 tableView.visible = true;
 webView.visible = false;
// setup the window
// create table view event listener
tableView.addEventListener('click', function(e)
 if (e.rowData.test) { 
  //alert( 'showTableView: '  );
 else if (e.rowData.url) { 
  //alert( 'showWebView: ' + e.rowData.url  );
— asked May 19th 2010 by Peruna Mustang
  • backbutton
  • iphone
  • mobile
  • tab

1 Answer

  • Accepted Answer

    The only way I know to do that would be to replace that button with your own button. There's a blur and close event for a window, but I don't think it fires in time to do a preventDefault on it and use your own function.

    Something like this should work:

    var win = Ti.UI.currentWindow;
    var b = Titanium.UI.createButton({title:'title'});
    b.addEventListener('click', function()
        // do something
    win.leftNavButton = b;
    — answered May 19th 2010 by Dan Giulvezan
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.