objective c - How to received alert() action from javascript into Cocoa application via WebView -


i develop cocoa application webview. can evaluate javascript html file using evaluatewebscript:

but need receive alert() event javascript display in cocoa's nsalertsheet.

how cocoa development ?

you need set object webuidelegate of webview (using setuidelegate: method) , in object implement ‑webview:runjavascriptalertpanelwithmessage:initiatedbyframe: delegate method. method called when page loaded webview calls alert() javascript function.

in implementation of delegate method, should display alert. alert should:

  1. display exact message string passed in method
  2. indicate message comes javascript
  3. contain 1 button, ok button

here basic example:

- (void)webview:(webview *)sender runjavascriptalertpanelwithmessage:(nsstring *)message {     nsalert* jsalert = [nsalert alertwithmessagetext:@"javascript"                                        defaultbutton:@"ok"                                       alternatebutton:nil                                           otherbutton:nil                             informativetextwithformat:@"%@", message];     [jsalert beginsheetmodalforwindow:sender.window modaldelegate:nil didendselector:null contextinfo:null]; } 

Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -