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

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

问题描述

我已经尝试通过 webview.request.URL 获取我的 UIWebView 的当前 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 的版本更加简洁.我建议大家使用那个而不是这个

你可以试试这个:

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天全站免登陆