我有一个自定义alertvew,当在uiwebview调用中按下按钮时javascript:
function doSomething(event){ 警报(“简单测试”); 返回false; } 我希望那个“警报”打开我的自定义uialert。 可能吗? 感谢
答案 0 :(得分:0)
找到适合我的代码:
@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];
UIImage *theImage = [UIImage imageNamed:@"MdC_Base_PopUp.png"];
theImage = [theImage stretchableImageWithLeftCapWidth:16 topCapHeight:16];
CGSize theSize = [dialogue frame].size;
UIGraphicsBeginImageContext(theSize);
[theImage drawInRect:CGRectMake(0, 0, dialogue.frame.size.width, dialogue.frame.size.height)];
theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
dialogue.layer.contents = (id)[theImage CGImage];
[dialogue show];
[dialogue autorelease];
}
@end