获取UIWebView的当前URL [英] Get current URL of UIWebView

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

问题描述

我已尝试使用以下内容获取 UIWebView 的当前网址: webview.request.URL
不幸的是 NSURL 是空的。这里有什么不对吗?我正在使用Xcode 3.2.2 beta 5.

I already tried getting the current URL of my UIWebView with: webview.request.URL. Unfortunately the NSURL was empty. Anything wrong here? I am working with Xcode 3.2.2 beta 5.

上面的代码应该在 UIWebView 委托中执行 didStartLoad

The code above should be executed in the UIWebView delegate didStartLoad.

推荐答案

马特的版本更清洁。我建议大家使用那一个而不是这个



你可以试试这个:

Matt's version is much cleaner. I recommend everyone to use that one instead of this

You could try this:

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

这篇关于获取UIWebView的当前URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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