Titanium Community Questions & Answer Archive

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

Can I use the HTML title (from a remote url) in the title bar of my app?

I have a web view, and I'd like to use the HTML title in the title bar of the app.

Any examples would be great.

Thanks,

Peter

— asked May 31st 2010 by Peter janett
  • html
  • remote
  • title
  • url
0 Comments

3 Answers

  • The easiest way to do this.

    In your webview js:

    window.onload = function()
    {
       Ti.App.fireEvent("set_title",{title:document.title});
    }
    

    this will fire an app event with the document title when the window is loaded.

    in your app.js:

    Ti.App.addEventListener('set_title',function(e)
    {
        win.title = e.title;
    });
    

    Note: win needs to point to your appropriately named window object to set.

    This will listen for the app event and set the windows title.

    — answered May 31st 2010 by Jeff Haynie
    permalink
    1 Comment
    • Thanks so much for the quick response. I think I'm almost there.

      Here's my code from app.js:

      var win3 = Titanium.UI.createWindow({
      backgroundColor:'#fff',
      url: 'pages/store.js'
      });

      var tab3 = Titanium.UI.createTab({
      icon:'images/headphones.png',
      title:'Store',
      window:win3
      });

      Ti.App.addEventListener('set_title',function(e)
      {
      win3.title = e.title;
      });


      And the code from pages/store.js:
      var window = Titanium.UI.currentWindow;
      var webview = Titanium.UI.createWebView({ url:'http://developer.appcelerator.com'});
      window.onload = function()
      {
      Ti.App.fireEvent("set_title",{title:document.title});
      }
      window.add(webview);


      Can you see what I'm missing?

      Again, thanks so much for your help!

      Peter

      — commented June 2nd 2010 by Peter janett
  • I think I've determined that the issue I'm having is not part of the function, but it's that the title value is not coming in from the webview DOM.

    In other words, the issue is that title:document.title is NOT being set.

    I tried alerting this right in the web view window, and it did not work.

    So, anyone know how to get the webview title into a var within Titanium Mobile?

    Thanks,

    Peter

    — answered July 26th 2010 by Peter janett
    permalink
    0 Comments
  • Peter, You can't with remote url but there's a work-around. My app using the same practice to trigger twitter Xauth share, email share, changing article font-sizes, load gallery and video player. All from a remote webview.

    Have a look at the solution on last post here
    http://developer.appcelerator.com/question/45251/access-titanium-api-from-webviews-javascript

    — answered July 26th 2010 by Daniel Lim
    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.