I was develop some Cocoa application with WebView. Now I can evaluate javascript to HTML file by using evaluateWebScript:
But I need to receive an alert() event from javascript to display in Cocoa’s NSAlertSheet.
How to do with cocoa development ?
You need to set an object as the
WebUIDelegateof theWebView(using thesetUIDelegate:method) and in that object implement the‑webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:delegate method. This method will be called when a page loaded into theWebViewcalls thealert()JavaScript function.In your implementation of the delegate method, you should display an alert. The alert should:
Here is a basic example: