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:
- display exact message string passed in method
- indicate message comes javascript
- 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
Post a Comment