开发者

Creare a custom action for an existing button in a webview

开发者 https://www.devze.com 2023-03-03 13:02 出处:网络
I\'m displaying an URL on a webview, and on that page there is a button. How can I customi开发者_StackOverflow中文版ze the action that occurs when that button is pressed?You controller has to respond

I'm displaying an URL on a webview, and on that page there is a button. How can I customi开发者_StackOverflow中文版ze the action that occurs when that button is pressed?


You controller has to respond to <UIWebViewDelegate>.

Then, override this method:

- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {

    if (navigationType == UIWebViewNavigationTypeLinkClicked) 
    {
        NSURL *URL = [request URL]; 
        if ([[URL absoluteString] rangeOfString:@"http://give.it.a.custom.url.to.identify.this.action"].length > 0)   
         {
             // your custom action here
         }

        return NO;
    }   
    return YES;   
}

Don't forget the [youWebView setDelegate:self];.

0

精彩评论

暂无评论...
验证码 换一张
取 消