【问题标题】:How to get the url that UIWebView is loading?如何获取 UIWebView 正在加载的 url?
【发布时间】:2012-07-09 08:21:19
【问题描述】:

在我的 WebView 中,当用户单击 WebView 中的链接时,该属性在哪里?我查看了文档并尝试了类似

[webView.request.URL description]
webView.request.URL.absoluteURL or absoluteString

,一切都是空白的。谢谢!

【问题讨论】:

标签: iphone


【解决方案1】:

像这样实现委托函数

- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType 
{
    if(navigationType == UIWebViewNavigationTypeLinkClicked)
    {
        // Its following the click on some link on the loaded webpage
        NSString  *strLink = [[request URL] absoluteString]; // Clicked Link URL
    }
    return YES; // return YES if you allow the page to load else return NO  
}

希望对你有所帮助。

【讨论】:

    【解决方案2】:

    当用户点击任何链接时,您需要捕获 webview 委托函数

    - (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
      NSURL *url = [request URL];
      NSString *link =   [url absoluteString];
      return YES;   
    }
    

    【讨论】:

      【解决方案3】:

      不妨试试这个:

      NSString *link = [webView.request.URL absoluteString];
      

      希望这会有所帮助!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-08-04
        • 2011-09-12
        相关资源
        最近更新 更多