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
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.
-
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
-
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