UIWebView click action response to invoke custom codepage

I am looking for a way to listen for an action in a UIWebView. For example: When I click a link or button inside a UIWebView, I want to invoke a new native component, such as a comment page. Or. take some other action, such as changing the navigationBar element.

+4
source share
1 answer

Yes you can do it. Implement

โ€“ webView:shouldStartLoadWithRequest:navigationType: 

This delegate . This method is called every time your webview is about to make a request. So now, when someone clicks a button or hyperlink on your web page, you will receive a call to this method. Once you catch this challenge, you can do whatever you want. How to redirect a link through your own servers or register a request to your server about user activity or in your case display a comment page or change the navigation bar, etc.

Example. Here you are trying to intercept any links clicked on your web page and pass them through myMethodAction .

 - (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType { if(navigationType == UIWebViewNavigationTypeLinkClicked) { if(overrideLinksSwitch.on == TRUE) { [self myMethodAction]; [myWebView stopLoading]; return YES; } else { return YES; } } return YES; } 

Hope this helps ...

+4
source

Source: https://habr.com/ru/post/1385271/


All Articles