解决此问题的更好方法是为该方法创建UIWebView的类别
webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:
这样您就可以以任何方式处理警报事件.我这样做是因为我不喜欢UIWebView的默认行为,因为它将源文件名放在UIAlertView标题中.类别看起来像这样,
@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:nil message:message delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles:nil]; [dialogue show]; [dialogue autorelease]; } @end