Search code examples
iphoneiosuiwebviewuiwebviewdelegate

Get updated url from uiwebview


I have a uiwebview I open http://google.com in it. Then I type something in google search bar and search for something. I want to get that updated url that is generated as a result of my search on google.

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self setUrlAddress:@"http://google.com.pk"];
    // Do any additional setup after loading the view from its nib.
    NSURL *url = [NSURL URLWithString:self.urlAddress];
    //URL Requst Object
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
    //Load the request in the UIWebView.
    [self.webView setScalesPageToFit:YES];
    [self.webView loadRequest:requestObj];


}

- (void)webViewDidStartLoad:(UIWebView *)webView{
    [appDelegate showActivityView:self.view];
}

- (void)webViewDidFinishLoad:(UIWebView *)webView{
    [appDelegate hideActivityView];
}

Solution

  • Try this

    NSString *currentURL = [webView stringByEvaluatingJavaScriptFromString:@"window.location.href"];
    

    Hope it will work for you