Titanium Community Questions & Answer Archive

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

Change tabs from within webview

Hi there,

I'm just coming from jQTouch, and am attempting to recreate my app in titanium using webviews (just to start whilst I get to grips with the software).

I'm working with the kitchen sink at the moment, and have been able to get my webviews setup with tabs, but wondered:

How can I change tabs from within the webview html?

ie. I've split my app into 4 html pages (across 4 tabs). Some of these pages have html buttons (a href) in them. Is there an onclick action or something I can use to click one of these buttons in the webview html that will change the tab in titanium?

My tab items are setup as so:

var win1 = Titanium.UI.createWindow();

var tab1 = Titanium.UI.createTab({
    icon:'images/tabs/card1.png',
    title:'Card 1',
    window:win1
});

var webview1 = Titanium.UI.createWebView({url: 'index.html'});

win1.add(webview1);
win1.hideNavBar();
— asked November 2nd 2010 by Glen McPherson
  • links
  • navigation
  • tabs
  • webview
0 Comments

1 Answer

  • Hi again,
    I've been through these threads for hours, and think i've got the general gist of it (customising some existing code). Would someone know if this is the correct way of doing things?

    Thanks!
    Glen

    IN APP.JS

    Ti.App.addEventListener('gotoCard3', function() 
    { 
         tabGroup.setActiveTab(2);
    });
    

    IN HTML

    <a href="#" class="btn" onClick="Ti.App.fireEvent('gotoCard3');">Card 3 Link</a>
    
    — answered November 3rd 2010 by Glen McPherson
    permalink
    1 Comment
    • // add return false; pass data back
      <a href="#" class="btn" onClick="Ti.App.fireEvent('gotoCard', {card:'3'}); return false;">Card 3 Link</a>
      

      in app.js, something like this

      Ti.App.addEventListener('gotoCard', function(data) 
      { 
           var tabId = data.card-1
           tabGroup.setActiveTab(tabId);
      });
      

      — commented November 3rd 2010 by Aaron Saunders
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.