Can I handle alert inside UIWebViewDelegate?

后端 未结 3 1631
长发绾君心
长发绾君心 2020-11-30 09:24

I can see the alert message inside my UIWebView

3条回答
  •  萌比男神i
    2020-11-30 10:10

    A better solution to this problem is to create a Category for UIWebView for the method

    webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:
    

    So that you can handle the alert event in any way that you'd like. I did this because I don't like the default behavior of UIWebView when it puts the filename of the source in the UIAlertView title. The Category looks something like this,

    @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
    

提交回复
热议问题