Objective c 如何在OS X WebView中显示/处理JavaScript警报?

Objective c 如何在OS X WebView中显示/处理JavaScript警报?,objective-c,macos,webview,rubymotion,Objective C,Macos,Webview,Rubymotion,我有一个OSX应用程序,我正在技术上实现它,但这并不重要。WebView包装了一个web应用程序,该应用程序在允许您执行操作之前触发JavaScript警报。它在普通web浏览器中正常工作,但不会显示在WebView中 我缺少什么配置设置,或者如何处理此功能 @web_view = WebView.alloc.initWithFrame(NSMakeRect(0, 0, 1000, 500)) @web_view.setAutoresizingMask(NSViewMinXMargin|NSVi

我有一个OSX应用程序,我正在技术上实现它,但这并不重要。WebView包装了一个web应用程序,该应用程序在允许您执行操作之前触发JavaScript警报。它在普通web浏览器中正常工作,但不会显示在WebView中

我缺少什么配置设置,或者如何处理此功能

@web_view = WebView.alloc.initWithFrame(NSMakeRect(0, 0, 1000, 500))
@web_view.setAutoresizingMask(NSViewMinXMargin|NSViewMaxXMargin|NSViewMinYMargin|NSViewMaxYMargin|NSViewWidthSizable|NSViewHeightSizable)
@web_view.setMainFrameURL('http://localhost:3000')
@mainWindow.contentView.addSubview(@web_view)

为了处理JavaScript警报和确认对话框,您需要指定:

…并实施这些方法:

def webView(web_view, runJavaScriptAlertPanelWithMessage: message, initiatedByFrame: frame)
  alert = NSAlert.new
  alert.addButtonWithTitle("OK")
  alert.setMessageText(message)
  alert.runModal
end

def webView(web_view, runJavaScriptConfirmPanelWithMessage: message, initiatedByFrame: frame)
  result = NSRunInformationalAlertPanel("JavaScript", # title
                                        message,      # message
                                        "OK",         # default button
                                        "Cancel",     # alt button
                                        nil)
  NSAlertDefaultReturn == result
end
def webView(web_view, runJavaScriptAlertPanelWithMessage: message, initiatedByFrame: frame)
  alert = NSAlert.new
  alert.addButtonWithTitle("OK")
  alert.setMessageText(message)
  alert.runModal
end

def webView(web_view, runJavaScriptConfirmPanelWithMessage: message, initiatedByFrame: frame)
  result = NSRunInformationalAlertPanel("JavaScript", # title
                                        message,      # message
                                        "OK",         # default button
                                        "Cancel",     # alt button
                                        nil)
  NSAlertDefaultReturn == result
end