在 Web 视图 swift 中获得 URL 次点击(共 link 次)
Get URL of link clicked in a web view swift
我在 Swift 中的 UIWebView
中从 url 加载了一个 html 页面,我想知道如何获得 URL单击加载新页面后,我的 html 中的 link。经过一番搜索后,我发现了 shouldStartLoadWithRequest
和 LinkClicked
之类的东西,但它并不是很有帮助。
我使用了 WKWebView 并且通过一些脚本我注入了一些 CSS 所以点击后不需要得到 url 。
我知道回复晚了,但我想这可能就是您要找的。 request.URL!给你 URL 到任何被点击的东西。
func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
let scheme = request.URL!
NSLog(scheme)
}
使用此代码:假设要链接的 url 是 (www.google.com)
func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool {
let urlString = request.url?.absoluteString
print(urlString) // "www.google.com"
return true
}
我在 Swift 中的 UIWebView
中从 url 加载了一个 html 页面,我想知道如何获得 URL单击加载新页面后,我的 html 中的 link。经过一番搜索后,我发现了 shouldStartLoadWithRequest
和 LinkClicked
之类的东西,但它并不是很有帮助。
我使用了 WKWebView 并且通过一些脚本我注入了一些 CSS 所以点击后不需要得到 url 。
我知道回复晚了,但我想这可能就是您要找的。 request.URL!给你 URL 到任何被点击的东西。
func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
let scheme = request.URL!
NSLog(scheme)
}
使用此代码:假设要链接的 url 是 (www.google.com)
func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool {
let urlString = request.url?.absoluteString
print(urlString) // "www.google.com"
return true
}