Get current URL of UIWebView Get current URL of UIWebView ios ios

Get current URL of UIWebView


window.location via JS didn't work reliably for me, but this did:

currentURL = currentWebView.request.URL.absoluteString;

Credit:http://mohrt.blogspot.com/2008/10/getting-url-from-uiwebview.html


here's the code I use to grab the url every time you navigate to a different link within the webview:

- (void)webViewDidFinishLoad:(UIWebView *)aWebView{  self.url = aWebView.request.mainDocumentURL;}


Matt's version is much cleaner. I recommend everyone to use that one instead of this

You could try this:

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