- 遵循WKUIDelegate方法
self.webView.uiDelegate = self
- 实现
func webView(_ webView: WKWebView, runJavaScriptAlertPanelWithMessage message: String, initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping () -> Void) {
let alertController = UIAlertController.init(title: "", message: message, preferredStyle: .alert)
alertController.addAction(UIAlertAction.init(title: "OK", style: .cancel, handler: { (_) in
completionHandler()
}))
self.present(alertController, animated: true) {
}
}