Ankur Arya
Ankur Arya

Reputation: 4723

get current url in UIWebView

I am using a UIWebView and loading an NSURL there are 4 links in that page when I click a link this method is called. which is fine

-(BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType 
{ 
}

after moving to next page my UINavigationBar shows a back button

 -(void)backButtonClicked
{
if ( myWebView.loading) 
{
    [myWebView goBack];
       } 
}

which takes me back to the main page, but if I again click the same link no delegate method is called. why is that? I need to get the current url every time I click a link.

Upvotes: 1

Views: 1595

Answers (3)

Borut
Borut

Reputation: 8138

Try this in delegate...

- (void)webViewDidFinishLoad:(UIWebView *)webView 
{
    NSLog(@"Webview url: %@",webView.request.URL.absoluteString);
}

Upvotes: 1

Adiee
Adiee

Reputation: 147

You can try this :

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

Upvotes: 2

fibnochi
fibnochi

Reputation: 1113

You have to store all the opened URLs in an array and when back button check if the tapped link is same as of stored link in array on last object then reload the web view.

Upvotes: 0

Related Questions