xcode 获取当前 URL (UIWebView)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8875658/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 23:00:45  来源:igfitidea点击:

Get Current URL (UIWebView)

objective-cxcodeurluiwebview

提问by JTApps

Simply enough, I need to know how to obtain the current URL that the UIWebView is in. That way, I would be able to add such features as bookmarking, sharing, etc.

很简单,我需要知道如何获取 UIWebView 所在的当前 URL。这样,我就可以添加书签、共享等功能。

The crux of the question is, what can I do to obtain the current URL of the webvew?

问题的关键是,如何获取webvew的当前URL?

EDIT: Solution:

编辑:解决方案:

NSString *currentURL = myWebView.request.URL.absoluteString;

回答by Raptor

NSString *currentURL = myWebView.request.URL.absoluteString;

回答by Ecarrion

[[[web request] URL] absoluteString]

Will give you the current url as a String.

会给你当前的 url 作为字符串。

回答by Den

In Swift if you need to get your URL you need to write this block of code:

在 Swift 中,如果您需要获取 URL,则需要编写以下代码块:

func webViewDidFinishLoad(webView: UIWebView) {
    let currentURL = webView.request?.mainDocumentURL
    print(currentURL)
}