【问题标题】:Javascript alert not showing in embedded WebView OSXJavascript 警报未显示在嵌入式 WebView OSX 中
【发布时间】:2015-01-02 12:00:44
【问题描述】:

我有一个嵌入的 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 的任何警报

【问题讨论】:

    标签: javascript macos cocoa swift webview


    【解决方案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 {
    
                 }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-21
      • 2018-06-26
      • 1970-01-01
      • 2011-11-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多