2

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];
}
  • You need to use JaveScript Injection for that!NSString *stringURL = [webView stringByEvaluatingJavaScriptFromString:@"window.location.href"]; – Kiran Mar 01 '13 at 11:41

4 Answers4

2

Try this

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

Hope it will work for you

Rushabh
  • 3,208
  • 5
  • 28
  • 51
1

Below is a correct answer but its not perfectly working for Facebook and youtube

NSSTRing * currentURL = webView.request.URL.absoluteString;

If anyone knows a better answer, please share.

Anshul Goyal
  • 73,278
  • 37
  • 149
  • 186
neha
  • 11
  • 1
0
- (void)viewDidLoad
{
    [super viewDidLoad];
    NSString *urlAddress = [NSString stringWithFormat:@"http://www.google.com/pk];
//Create a URL object.
    NSURL *url = [NSURL URLWithString:urlAddress];
//URL Requst Object
   NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
   [webView loadRequest:requestObj];

}
iPatel
  • 46,010
  • 16
  • 115
  • 137
0

try this delegate method :

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

you can get hold of request and nslog that request .

Illep
  • 16,375
  • 46
  • 171
  • 302
Naveen Pathiyil
  • 826
  • 1
  • 7
  • 8