0

I need to display webpage using URL. From that page I want to remove one link control from that html page. Is it possible? I am opening it with this kind of code.

NSString *urlAddress = @"http://myurl.com";
NSURL *url = [NSURL URLWithString:urlAddress];
Krutika Sonawala
  • 1,065
  • 1
  • 12
  • 30

2 Answers2

1

We can do this.

First we should know about the UIWebViewDelegate methods

First create BOOL

ViewController.h

@property (nonatomic) BOOL ret;

ViewController.m

@synthesize ret;

Set BOOL to NO in below delagte method

- (void)webViewDidFinishLoad:(UIWebView*)webView {
   // Sent after a web view finishes loading a frame. 
   ret = NO;
}

Then If we return NO in below delegate method, this will prevent the user from viewing link

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

Dave DeLong's Disable Link in UIWebView answer

Removing hyper links from a URL shown in UIWebView

Community
  • 1
  • 1
user3182143
  • 9,459
  • 3
  • 32
  • 39
1

If you want to disable ALL links, see the answer from user3182143...

If you only want to disable a specific link, you can still use those methods - you will just need to evaluate the request part of shouldStartLoadWithRequest:(NSURLRequest *)request and decide whether to return YES or NO

If you want a specific link to look different, you'll need to modify the html. Couple ways to do so, but we really need more information about exactly what you are trying to do.

Are you displaying ONE specific web page? And all you need to do is change ONE link in that ONE page, and you're done? Are you displaying a series of pages? Do you have any control of the pages? And so on.

I'd suggest you start searching for and reading about uiwebview insert html or uiwebview insert javascript

DonMag
  • 69,424
  • 5
  • 50
  • 86