Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do I get the title of a URL

I have a URL and I will show the URL inside a ModalViewController. I would like to set the title of this URL in the navigation bar.

Inside the ModalViewController I have a UIWebView to display the site. Is there a way to extract the title of this site via UIWebView? Did a bit of research and it seems that I would like to use some javascript inside the (void)webViewDidFinishLoad:(UIWebView *)webView Not sure though how it works.

like image 256
adit Avatar asked May 28 '11 15:05

adit


People also ask

What is the title of a URL?

A website title identifies what the web page is about for both web users and search engines. On web browsers, the website title appears at the top of the tab or window, and in search results website titles display as bold hyperlinked texts.

How do I get the page title from a URL?

In order to get/retrieve web page title from url, you have to use function file_get_contents() and regular expression together. Here is the php function to retrieve the contents found between <title> </title> tag. <?

How do you look up a URL?

Get a page URL On your computer, go to google.com. Search for the page. In search results, click the title of the page. At the top of your browser, click the address bar to select the entire URL.


1 Answers

Try this:

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

Taken from: http://blog.mcohen.me/2008/12/12/getting-the-title-of-a-web-view-in-cocoa-touch/

like image 128
Ben Avatar answered Oct 13 '22 00:10

Ben