【发布时间】:2020-04-01 05:19:21
【问题描述】:
我的网页有多个确认对话框。它们属于不同的网址
window.confirm("Hello") -> /hello
window.confirm("Exit") -> /confirm
我有我的视图控制器:
class View2Controller: UIViewController, WKUIDelegate {
var webView: WKWebView!
...
override func viewDidLoad() {
webView = WKWebView(frame: CGRect(x: 0, y: 0, width: view.frame.size.width, height: view.frame.size.height), configuration: WKWebViewConfiguration())
self.view.addSubview(webView)
let myURL = URL(string:"https://www.myweb.com")
let myRequest = URLRequest(url: myURL!)
webView.uiDelegate = self
webView.load(myRequest)
... ...
func webView(_ webView: WKWebView, runJavaScriptConfirmPanelWithMessage message: String, initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping (Bool) -> Void) {
let ac = UIAlertController(title: "Title", message: message, preferredStyle: .alert)
ac.addAction(UIAlertAction(title: "OK", style: .default, handler: { (UIAlertAction) in
...
}))
ac.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
self.present(ac, animated: true)
completionHandler(true)
}
我是否可以仅在 /confirm URL 中使用 iOS 警报来确认退出,并为 Hello 使用网络确认对话框?
【问题讨论】:
标签: ios swift xcode webview wkwebview