Titanium Community Questions & Answer Archive

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

Passing a url from tableview to webview

I know that this question has been asked and answered many times on this forum but unfortunately I still have not been able to grasp the concept correctly for my use case and I was hoping someone may be able to help.

My setup is a shows.js page that builds a tableview of all the shows being pulled from a database. The variable [path] contains a url that I would like to open in a webview when a row is clicked.

When I click on a table row it animates the new window across but does not load the webview. I would be very grateful if someone could help to point out where I am going wrong.

The code I am using to do this is:

xhr.onload = function() {

  Ti.API.info(this.responseText);
  var data = JSON.parse(this.responseText);
  Ti.API.info(data);

for (var c=0;c<data.length;c++){

var row = Ti.UI.createTableViewRow();

    var label = Ti.UI.createLabel({
        text: data[c]['title'],
    });

    row.add(label);
    row.url = data[c]['path'];
}

var tableview = Titanium.UI.createTableView({
    data:data,
    style:Titanium.UI.iPhone.TableViewStyle.PLAIN,
    backgroundColor:'transparent',
    headerView:headerView,
    footerView:footerView,
    maxRowHeight:140,
    minRowHeight:70,
    separatorStyle: Ti.UI.iPhone.TableViewSeparatorStyle.NONE
});

tableview.addEventListener('click',function(e)
{ 
  Ti.API.info(e.rowData);

if (e.rowData.url)
    {

        var win = Titanium.UI.createWindow({
            title:e.rowData.title
        });

        var webview = Titanium.UI.createWebView({
        url:e.rowData.url
        });

        win.add(webview);
        Titanium.UI.currentTab.open(win,{animated:true});

    }
});

win.add(tableview);

} // end of xhr.onload function
— asked July 20th 2010 by Gregg Coppen
  • mobile
  • variables
  • webview
0 Comments

1 Answer

  • Accepted Answer

    i tried your code with fixed elements (url & title) it worked fine (webview show me the content of webview value.

    did you checked the content of the e.rowData.url ? (with Ti.API.info(e.rowData.url) for example)

    — answered July 20th 2010 by Stephane Pelamourgues
    permalink
    2 Comments
    • You are right Stephane, it works with fixed values…
      So with a bit more trial and error it seems that the relative urls were not being read correctly but as soon as I put the full url in front of the path variable, it works fine.

      Thanks for your help

      — commented July 20th 2010 by Gregg Coppen
    • hey can you please share what changes you did.i tried you code its working on iphone but not in android

      — commented June 7th 2013 by devyani p
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.