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.
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.
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. <?
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.
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With