views:

36

answers:

1

I'm having a problem with my UIWebView for my iPhone App... I am getting an alert thrown up with OK-Cancel button options, and I don't want the user to see this... But the web page automatically pops up an alert. How can I programmatically detect the Alert was thrown up and how do I click the cancel button on the alert?

Thanks, Matt

A: 

In a class derived from UIWebView, implement these methods:

- (void)webView:(id)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(id)frame {}
- (BOOL)webView:(id)sender runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(id)frame { return NO; }

While not strictly documented, you are not actually calling anything so it may be accepted.

Otherwise, you will have to find the javascript in the loaded page that is putting up the alert and remove it.

drawnonward
If the app store people find out, your app will be disallowed, because UIWebView is not designed to be subclassed.
Tom H
If you do not want to subclass, you could add those methods as a category to UIWebView. Either way, there is a possibility of rejection.
drawnonward