我想以使用HTML标签遵循代码的标签表单显示URL,因此请帮助我解决
<p> <span id="link" style="word-break:break-all;" ng-bind="link"></span> </p>
func webViewDidFinishLoad(_ webView: UIWebView)
{
let htmlString = liveWebView.stringByEvaluatingJavaScript(from: "window.someGlobalVariable")!
htmlString = webView.stringByEvaluatingJavaScript(from: "document.getElementById('Start').disabled = false;")!
print("******",htmlString)
}
let htmlString:String = webView.stringByEvaluatingJavaScript(from: "document.getElementById('link').innerHTML")!
使用 NSDataDetector
类可以匹配日期,地址,链接,电话号码和过境信息。参考。
let htmlString = "<p><a href="https://www.youtube.com/watch?v=i2yscjyIBsk">https://www.youtube.com/watch?v=i2yscjyIBsk</a></p>n"
let types: NSTextCheckingType = .Link
let detector = try? NSDataDetector(types: types.rawValue)
guard let detect = detector else {
return
}
let matches = detect.matchesInString(htmlString, options: .ReportCompletion, range: NSMakeRange(0, htmlString.characters.count))
for match in matches {
print(match.URL!)
}