iOS UIWebView custom alert style bullet box

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.