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

时间:2015-01-02 12:00:44

标签: javascript macos cocoa swift webview

我有一个嵌入式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

中解除警报

1 个答案:

答案 0 :(得分:1)

对其进行排序

 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 {

             }