How to use toStartLoadWithRequest method for UIWebView Delegate

I need to remove hyperlinks from the URL shown in UIWebView, and I reviewed this question: Removing hyperlinks from the URL shown in UIWebView .

I know that I need to use this method:

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

But I still have some problems.

Firstly, how can I avoid only certain links (for example: www.google.com).

Next, how do I avoid all the links in my UIWebView?

My code is as follows:

 [webUI loadHTMLString:[strDescription stringByDecodingHTMLEntities] baseURL:nil]; webUI.dataDetectorTypes = UIDataDetectorTypeNone; - (void)webViewDidFinishLoad:(UIWebView *)webView { NSLog(@"finish loading"); [webUI stringByEvaluatingJavaScriptFromString:@"document.styleSheets[0].addRule(\".active\", \"pointer-events: none;\");document.styleSheets[0].addRule(\".active\", \"cursor: default;\")"]; } - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { return YES; } 

Need to be guided. Thanks..

The HTML line looks like this:

 > <div style="font-family: Helvetica"><div style="color: #FFFFFF;"><div > style="font-family: Helvetica;"><p><span style="font-size: > 24px;"><strong>Optimal Performance Always</strong></span><span > style="font-size: 18px;"><br /></span></p><p><span style="font-size: > 18px;">The standard servicing package<a > href="http://www.google.com">www.google.com</a></div> 
+4
source share
1 answer

If you want to disable all links after loading the first page, you can add a property to store if the page has been loaded, and use its value in webView: shouldStartLoadWithRequest:

 @property(nonatomic) BOOL pageLoaded; // initially NO - (void)webViewDidFinishLoad:(UIWebView *)webView { NSLog(@"finish loading"); [webUI stringByEvaluatingJavaScriptFromString:@"document.styleSheets[0].addRule(\".active\", \"pointer-events: none;\");document.styleSheets[0].addRule(\".active\", \"cursor: default;\")"]; // after all your stuff self.pageLoaded = YES; } - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { return ! self.pageLoaded; } 

Please note that this does not hide links, it only makes web browsing not download them.

You can also check request.URL on webView: shouldStartLoadWithRequest: navigationType: only load specific pages. Another way is to check the value of the navigation Type:

 enum { UIWebViewNavigationTypeLinkClicked, UIWebViewNavigationTypeFormSubmitted, UIWebViewNavigationTypeBackForward, UIWebViewNavigationTypeReload, UIWebViewNavigationTypeFormResubmitted, UIWebViewNavigationTypeOther }; 
+3
source

All Articles