我正在使用以下代码通过SFSafariViewController
打开URL:
import UIKit
import SafariServices
class ViewController: UIViewController, UITextViewDelegate {
override func viewDidLoad() {
super.viewDidLoad()
openBrowser(url: "https://www.example.com")
}
fileprivate func openBrowser(url: String) {
let svc = SFSafariViewController(url: NSURL(string: url)! as URL, entersReaderIfAvailable: false)
svc.delegate = self
present(svc, animated: true, completion: nil)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
extension ViewController: SFSafariViewControllerDelegate {
func safariViewController(_ controller: SFSafariViewController, didCompleteInitialLoad didLoadSuccessfully: Bool) {
}
func safariViewController(_ controller: SFSafariViewController, activityItemsFor URL: URL, title: String?) -> [UIActivity] {
return []
}
func safariViewControllerDidFinish(_ controller: SFSafariViewController) {
}
}
效果很好。
但是,如果该网站包含带有target="_blank"
的链接,而我单击它,则没有任何反应。
我知道SFSafariViewController
不支持多个窗口或标签。
但是我认为应该有可能忽略target="_blank"
并像没有target="_blank"
一样打开链接。
有没有办法做到这一点?