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

标签 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

仍然没有发出任何警报

最佳答案

排序

 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 {

             }

关于嵌入式 WebView OSX 中未显示 Javascript 警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27741872/

相关文章:

javascript - Bootstrap 工具提示隐藏选择器/切换元素

objective-c - CoreAnimation : warning, 删除了未提交 CATransaction 的线程;

macos - 获取 LLDB 的 _remove_dead_weakref 错误

java - OS-X 上的 VTK Java、Cocoa 异常

objective-c - 将启用的 NSButton 绑定(bind)到 NSTextView 中的选择

swift - NSCollectionView - 自定义 View 项未连接或不会选择

标签上的 Javascript maxLength

javascript - JQuery 验证 - 模式规则无法像自定义正则表达式方法一样工作

javascript - Node.js 在循环中多次调用 MySQL 存储过程

xcode - NSBezierPath:如何使用 LineDashStyle 控制线段数量?