iPhone - UIWebview - 获取点击链接的URL [英] iPhone - UIWebview - Get the URL of the link clicked

查看:380
本文介绍了iPhone - UIWebview - 获取点击链接的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个包含文本字段的应用程序。顶部的按钮和他们下面的Web视图。
当用户在文本字段中输入URL并单击开始按钮时,它将开始在webview中加载页面。
当用户点击某个链接时,我想在文本字段中显示页面的URL(正在加载)。
如何获得点击链接的URL。

I'm creating an app which has a text field & go button on top and web view below them. When user enters URL in text field and clicks "Go" button, it will start loading the page in webview. When user clicks on some link, i want to show the URL of the page (being loaded) in the text field. How can I get that URL of the link clicked.

还有一些网站会重定向到其他网站。所以我的问题是如何在文本字段中显示正在加载的页面的URL?

Also some websites are there which will redirect to some other site. So my question is how to show the URL of the page being loaded in the text field?

推荐答案

在UIWebViewDelegate类中实现它

Implement this in your UIWebViewDelegate class

- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
    //CAPTURE USER LINK-CLICK.
      NSURL *url = [request URL];
      yourTextBox.text =   [url absoluteString];


      return YES;   
}

这篇关于iPhone - UIWebview - 获取点击链接的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆