Get current URL of UIWebView

后端 未结 14 1943
天命终不由人
天命终不由人 2020-11-29 16:08

I already tried getting the current URL of my UIWebView with: webview.request.URL. Unfortunately the NSURL was empty. Anything wrong h

相关标签:
14条回答
  • 2020-11-29 16:42
    - (void)webViewDidFinishLoad:(UIWebView *)webView{
         NSURL *currentURL = [[webView request] URL];
         NSLog(@"%@",[currentURL description]);
    
    }
    
    0 讨论(0)
  • 2020-11-29 16:44

    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;
    }
    
    0 讨论(0)
  • 2020-11-29 16:44

    IN Swift try this,

    func webViewDidFinishLoad(webView: UIWebView){
        println(WebView.request?.mainDocumentURL)
    }
    
    0 讨论(0)
  • 2020-11-29 16:46

    here the code i use :

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[[[webView request] URL] absoluteString]]];
    
    0 讨论(0)
  • 2020-11-29 16:47

    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

    0 讨论(0)
  • 2020-11-29 16:48

    To get current URL of the WKWebView and UIWebview

    Here is the code.

    if (self.wkWebView) {
       NSString  *URL = self.wkWebView.title;
    }else if(self.uiWebView) {
       NSString *URL = self.uiWebView.request.title;
    }
    
    0 讨论(0)
提交回复
热议问题