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

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

问题描述

我正在创建一个应用程序,它有一个文本字段 &顶部的 go 按钮和它们下方的 web 视图.当用户在文本字段中输入 URL 并单击Go"按钮时,它将开始在 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天全站免登陆