IOS中webview捕捉js中的alert 并修改标题和按钮

IOS中webview捕捉js中的alert 并修改标题和按钮

@interface UIWebView (JavaScriptAlert)   

- (void)webView:(UIWebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(id)frame;  

@end  

@implementation UIWebView (JavaScriptAlert)  

- (void)webView:(UIWebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(id)frame {  


    UIAlertView* customAlert = [[UIAlertView alloc] initWithTitle:@"提示信息" message:message delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];  

    [customAlert show];  

    [customAlert autorelease];  

}  
@end

把此方法直接放到webview.m文件中即可