Javascript 警报未显示在嵌入式 WebView 中 OSX

Javascript alert not showing in embedded WebView OSX

我有一个嵌入式 WebView toWeb 加载本地 HTML 文件。

我的警报 alert("Some message"); 没有触发

UIDelegate 设置在 toWeb

我在这里检查过: JavaScript alert() not working in embedded WebView

WKUIDelegate Protocol Reference

想出了

func toWeb(sender: WebView!, runJavaScriptAlertPanelWithMessage message: String!) {

    let myPopup:NSAlert = NSAlert()
    myPopup.addButtonWithTitle("OK")
    myPopup.messageText = "An alert";
    myPopup.informativeText = "Message"
    if myPopup.runModal() == NSAlertFirstButtonReturn {

    }

然而,我的嵌入式 WebVieW

仍然没有发出任何警报

已排序

 override func webView(sender: WebView!, runJavaScriptAlertPanelWithMessage 

    message: String!, initiatedByFrame frame: WebFrame!) {

            println("Alert sent")
            let myPopup:NSAlert = NSAlert()
            myPopup.addButtonWithTitle("OK")
            myPopup.messageText = "Title";
            myPopup.informativeText = "Message"
            if myPopup.runModal() == NSAlertFirstButtonReturn {

             }