Previously developed an app, because the company has written the web version of the content and the Android version of the app, I went in after the boss asked me to use the content of iOS directly, and do not need to build their own framework. I listen, laugh, this is not a uiwebview it? Simple!
But, TMD (o^o)! Things are not so simple, asked me to interact with the Web page, first encountered a custom Web page bullet frame problem, thought: Find the Web box to intercept, replace the box to write their own.
First, create the category of UIWebView Uiwebview+javascriptalert
1. Adding methods in. h
-(void) WebView: (UIWebView *) sender Runjavascriptalertpanelwithmessage: (NSString *) message Initiatedbyframe: (ID) frame;
2. Create a bullet box in. m and change the title
@implementation UIWebView (Javascriptalert)-(void) WebView: (UIWebView *) sender Runjavascriptalertpanelwithmessage: (NSString *) message initiatedbyframe: (ID) frame{ * Customalert = [[Uialertview alloc]initwithtitle:@ " you want to change the title "delegate: Nil Cancelbuttontitle:@ " OK " Otherbuttontitles:nil, nil]; [Customalert show]; } @end
Second, the agent method in UIWebView
-(BOOL) WebView: (UIWebView *) WebView shouldstartloadwithrequest: (nsurlrequest *) Request Navigationtype: ( Uiwebviewnavigationtype) Navigationtype
Interception in
if ([Request.mainDocumentURL.relativePath isequaltostring:@ "/alert"]) { [WebView Webview:webview runjavascriptalertpanelwithmessage:@ "123" initiatedbyframe: Nil]; return NO; }
iOS UIWebView custom alert style bullet box