Yasuhiro Kondo
Yasuhiro Kondo

Reputation: 197

Get current URL in UIWebview but it not respond

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

Answers (1)

Leo
Leo

Reputation: 24714

You can not get title of a website before you receive data from the URL.

So

  • Set your webview delegate to self

Then in

  • - webViewDidFinishLoad: to get title

Upvotes: 1

Related Questions