| 96 |
96 |
if let url = navigationAction.request.url { UIApplication.shared.open(url) } |
| 97 |
97 |
return nil |
| 98 |
98 |
} |
|
99 |
+ |
|
100 |
+ // --- Panneaux JavaScript natifs (indispensables : sans eux confirm() |
|
101 |
+ // --- ne s'affiche pas → le mode BYPASS et les confirmations restent morts) --- |
|
102 |
+ private func topVC(_ webView: WKWebView) -> UIViewController? { |
|
103 |
+ var vc = webView.window?.rootViewController |
|
104 |
+ while let p = vc?.presentedViewController { vc = p } |
|
105 |
+ return vc |
|
106 |
+ } |
|
107 |
+ func webView(_ webView: WKWebView, runJavaScriptAlertPanelWithMessage message: String, |
|
108 |
+ initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping () -> Void) { |
|
109 |
+ let a = UIAlertController(title: nil, message: message, preferredStyle: .alert) |
|
110 |
+ a.addAction(UIAlertAction(title: "OK", style: .default) { _ in completionHandler() }) |
|
111 |
+ guard let vc = topVC(webView) else { completionHandler(); return } |
|
112 |
+ vc.present(a, animated: true) |
|
113 |
+ } |
|
114 |
+ func webView(_ webView: WKWebView, runJavaScriptConfirmPanelWithMessage message: String, |
|
115 |
+ initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping (Bool) -> Void) { |
|
116 |
+ let a = UIAlertController(title: nil, message: message, preferredStyle: .alert) |
|
117 |
+ a.addAction(UIAlertAction(title: "Annuler", style: .cancel) { _ in completionHandler(false) }) |
|
118 |
+ a.addAction(UIAlertAction(title: "OK", style: .default) { _ in completionHandler(true) }) |
|
119 |
+ guard let vc = topVC(webView) else { completionHandler(false); return } |
|
120 |
+ vc.present(a, animated: true) |
|
121 |
+ } |
|
122 |
+ func webView(_ webView: WKWebView, runJavaScriptTextInputPanelWithPrompt prompt: String, |
|
123 |
+ defaultText: String?, initiatedByFrame frame: WKFrameInfo, |
|
124 |
+ completionHandler: @escaping (String?) -> Void) { |
|
125 |
+ let a = UIAlertController(title: nil, message: prompt, preferredStyle: .alert) |
|
126 |
+ a.addTextField { $0.text = defaultText } |
|
127 |
+ a.addAction(UIAlertAction(title: "Annuler", style: .cancel) { _ in completionHandler(nil) }) |
|
128 |
+ a.addAction(UIAlertAction(title: "OK", style: .default) { _ in completionHandler(a.textFields?.first?.text) }) |
|
129 |
+ guard let vc = topVC(webView) else { completionHandler(nil); return } |
|
130 |
+ vc.present(a, animated: true) |
|
131 |
+ } |
| 99 |
132 |
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, |
| 100 |
133 |
decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) { |
| 101 |
134 |
if let url = navigationAction.request.url, let host = url.host, |