问题如下图
解决方案
UIWebView 屏蔽 alert警告框
如果是网页内容里面的alert,我们可以等网页加载完毕,也就是在webViewDidFinishLoad中执行下面的js代码,就可以屏蔽alert了
myWebView stringByEvaluatingJavaScriptFromString:@"window.alert=null;"];
但上面的方法对于网页onLoad事件里面的alert就不起作用了
解决方法就是给UIWebView添加一个类别:
给工程添加JavaScriptAlert.h
@interface UIWebView (JavaScriptAlert)
- (void)webView:(UIWebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame;
- (BOOL)webView:(UIWebView *)sender runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame;
@end
给工程添加JavaScriptAlert.m文件
@implementation UIWebView (JavaScriptAlert)
- (void)webView:(UIWebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame {
/*
UIAlertView* dialogue = [[UIAlertView alloc] initWithTitle:nil message:message delegate:nil cancelButtonTitle:@"好" otherButtonTitles:nil];
[dialogue show];
[dialogue autorelease];
*/
}
- (BOOL)webView:(UIWebView *)sender runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame{
return NO;
}
@end
其实runJavaScriptAlertPanelWithMessage和runJavaScriptConfirmPanelWithMessage是WebUIDelegate的成员函数,详情可以查阅WebUIDelegate的帮助文档