Search code examples
javascriptuitableviewsafarititaniumbookmarks

JS - Get Current Website Name (Similar To Safari)


This is a tough one to explain, but I'll try my best! I'm programming my app in JavaScript, and I'm using the Titanium IDE.

So, I'm trying to create a bookmarks menu for my app. I need it to essentially get the name/content header of the website, and that way the title of the bookmark will look decent, rather than just taking the direct route and cramming the Url of the website into the table.

To give an example of what I'm talking about,

Notice The Naming Of Each Bookmark

If you look, you can see that it says Apple, not http://www.apple.com or apple.com, and that's what I'm trying to replicate. If there's a function you might have or know a little about, please include it! Otherwise, any input is helpful!

Thanks

UPDATE: I found a solution if I was using XCode, and also for Titanium, for those that are interested. I know that document.title is the key here, but running it in Titanium, however, it's a little different. I'll post my conclusions below!.


Solution

  • I found the solution!

    For Xcode:

    - (void)webViewDidFinishLoad:(UIWebView *)webView{
        NSString *theTitle=[webView stringByEvaluatingJavaScriptFromString:@"document.title"];
    }
    

    For Titanium:

    theTitle = webView.evalJS("document.title");