Remove AlertView Title in UIWebView
Background
The app uses webview to load web-page in iPad. When javascript call the function alert
, iPad will call a message, e.g.
As you can see, the title of alert view is the domain name of this page, but it's ugly or should be in secrecy. So the task is to hide or remove the title of the alert view.
Solution
We can add category to UIWebView to catch up the alert and show another new alert with no title.
@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* customAlert = [[UIAlertView alloc] initWithTitle:@""
message:message
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[customAlert show];
[customAlert release];
}
@end
Now we will get a new alert view with no title, but notice that the message will be in bold font.
Reference
Apple API Reference
Relevant problem on stackoverflow
Another solution on stackoverflow
Author And Source
この問題について(Remove AlertView Title in UIWebView), 我々は、より多くの情報をここで見つけました https://qiita.com/JasonChen/items/b236479719794ee78298著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .