         }
     }
 
+    func webView(_ webView: WKWebView,
+                 createWebViewWith configuration: WKWebViewConfiguration,
+                 for navigationAction: WKNavigationAction,
+                 windowFeatures: WKWindowFeatures) -> WKWebView? {
+        let schemes = ["http", "https"]
+        if navigationAction.targetFrame == nil,
+           let url = navigationAction.request.url,
+           let scheme = url.scheme,
+           schemes.contains(scheme) {
+            let svc = SFSafariViewController(url: url)
+            present(svc, animated: true, completion: nil)
+        }
+
+        return nil
+    }
+
     func loadWebView(force: Bool = false) {
         let authStr = "\(Preferences.username):\(Preferences.password)"
         let newTarget = "\(openHABRootUrl):\(authStr)"

import UIKit
import WebKit

class OpenHABWebViewController: UIViewController, WKNavigationDelegate, WKScriptMessageHandler {
    private var currentTarget = ""

    // https://developer.apple.com/documentation/webkit/wkscriptmessagehandler?preferredLanguage=occ


    func webView(_ webView: WKWebView, didReceive challenge: URLAuthenticationChallenge,
                 completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
        if let url = modifyUrl(orig: URL(string: openHABRootUrl)), challenge.protectionSpace.host == url.host {
            guard challenge.previousFailureCount == 0 else {
                completionHandler(.cancelAuthenticationChallenge, nil)
                return
            }
            let credential = URLCredential(
                user: Preferences.username,
                password: Preferences.password,
                persistence: .forSession
            )
            completionHandler(.useCredential, credential)
        } else {
            completionHandler(.performDefaultHandling, nil)
        }
    }

    func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
