在ios中用webview 中的confirm对话框时一般的title是xx.html 很不美观,为了美观我们有下面的方法来修正
我们在条用js方法:
function tt(){
confirm("确认提交?");
}
结果是:
添加下面的修正:
@interface UIWebView (JavaScriptAlert)
- (void)webView:(UIWebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame;
- (BOOL)webView:(UIWebView *)sender runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame;
- (NSString *) webView:(UIWebView *)view runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(NSString *)text initiatedByFrame:(WebFrame *)frame;
@end
@implementation UIWebView (JavaScriptAlert)
static BOOL diagStat = NO;
- (void)webView:(UIWebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame {
UIAlertView* customAlert = [[UIAlertView alloc] initWithTitle:@"MEOA"
message:message
delegate:nil
cancelButtonTitle:@"确定"
otherButtonTitles:nil];
[customAlert show];
[customAlert autorelease];
}
- (NSString *) webView:(UIWebView *)view runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(NSString *)text initiatedByFrame:(WebFrame *)frame {
return @"";
}
- (BOOL)webView:(UIWebView *)sender runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame {
UIAlertView *confirmDiag = [[UIAlertView alloc] initWithTitle:nil
message:message
delegate:self
cancelButtonTitle:@"取消"
otherButtonTitles:@"确定", nil];
[confirmDiag show];
while (confirmDiag.hidden == NO && confirmDiag.superview != nil) {
[[NSRunLoop mainRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.01f]];
}
[confirmDiag release];
return diagStat;
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0){//取消;
diagStat = NO;
}
else if (buttonIndex == 1) {//确定;
diagStat = YES;
}
}
@end
效果: