ios
ios

Reputation: 975

Get url when a link is clicked in UIWebView

I want to get the url of the link when it is clicked in UIWebView .

I am using this code

  NSString *currentURL = [NSString stringWithFormat:@"%@", webview.request.URL.absoluteString];

        NSLog(@"Current URL == %@",currentURL);

It gives me null

Current URL == (null)

Upvotes: 1

Views: 678

Answers (1)

Maulik Patel
Maulik Patel

Reputation: 397

Try this In Webview Method :

     - (BOOL) webView: (UIWebView *) webView shouldStartLoadWithRequest: (NSURLRequest *) request navigationType: (UIWebViewNavigationType) navigationType{
             NSURL *url = request.URL;
             NSLog(@"%@", url.absoluteString);
            NSURL *url = request.URL;
            NSLog(@"%@", url.absoluteString);
            if ([url.host containsString:@"www.google.co.in"])
            {
               nslog(@"Google")
            }else{
            }
}

Upvotes: 1

Related Questions