我也用过这个:
@interface UIWebView (JavaScriptAlert)
- (void)webView:(UIWebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame;
@end
@implementation UIWebView (JavaScriptAlert)
- (void)webView:(UIWebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame {
UIAlertView *dialogue = [[UIAlertView alloc] initWithTitle:@"My Alert Title" message:message delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:nil];
[dialogue show];
}
答案 0 :(得分:0)
您必须使用UIAlertView的委托
- (void)webView:(UIWebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame {
UIAlertView *dialogue = [[UIAlertView alloc] initWithTitle:@"My Alert Title" message:message delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:nil];
dialogue.tag = 1;
[dialogue show];
}
-(void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (alertView.tag == 1) {
if (buttonIndex == alertView.cancelButtonIndex) {
//Do something here
}
}
}
答案 1 :(得分:0)
您可以在Javascript中显示提醒 - 这看起来与UIAlertView
完全相同。然后在解除警报时,将用户重定向到Javascript中的“someaction://”。在设备上,实现UIWebViewDelegate
的{{1}},如下所示:
webView:shouldStartLoadWithRequest:navigationType: