Reputation: 197
I create app to use UIWebview and show log to url if touch in content in UIWebview. this is my code
- (void)viewDidLoad {
[super viewDidLoad];
NSURL *url1 =[NSURL URLWithString:@"MyWebSite"];
NSURLRequest *request1 = [NSURLRequest requestWithURL:url1];
[_webView1 loadRequest:request1];
NSURL *url2 =[NSURL URLWithString:@"MyWebsite2"];
NSURLRequest *request2 = [NSURLRequest requestWithURL:url2];
[_webView2 loadRequest:request2];//url menu 2
NSString *currentURL = [_webView1 stringByEvaluatingJavaScriptFromString:@"document.title"];
NSLog(@"%@",currentURL);
}
but I touch the content log is not print and change webview log is print (null) sorry for my poor English.
Upvotes: 0
Views: 85
Reputation: 24714
You can not get title of a website before you receive data from the URL.
So
webview delegate
to self
Then in
- webViewDidFinishLoad:
to get titleUpvotes: 1