开发者

Creare a custom action for an existing button in a webview

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜