How to stop loading images in UIWebView?

I want to use UIWebView to load html url, but don't load image in html. I need a UIWebView to display plain text in html. For some reason, I am unable to change the html content before loading.

Is there any method for doing this?


source to share

2 answers

- (NSCachedURLResponse*)cachedResponseForRequest:(NSURLRequest*)request
    NSURL *url = [request URL];
    BOOL blockURL = [[FilterMgr sharedFilterMgr] shouldBlockURL:url];
    if (blockURL) {
        NSURLResponse *response =
              [[NSURLResponse alloc] initWithURL:url

        NSCachedURLResponse *cachedResponse =
              [[NSCachedURLResponse alloc] initWithResponse:response
                             data:[NSData dataWithBytes:" " length:1]];

        [super storeCachedResponse:cachedResponse forRequest:request];

        [cachedResponse release];
        [response release];
    return [super cachedResponseForRequest:request];


This is the code for part of this

Hope it helps



Then remove all image tages using below code then after load your html string into webview

NSString *str =@"<ul><img src=\"some url\"/><li>Tiny pores in leaves or stems, which water and gas can pass. </li><li>Plants can reduce the amount of water that is passed by closing the stomates during the hottest parts of the day or curling their leaves up to reduce exposure.</li></ul>";
    NSRange r;
    while ((r = [str rangeOfString:@"<img[^>]+>" options:NSRegularExpressionSearch]).location != NSNotFound)
        str = [str stringByReplacingCharactersInRange:r withString:@""];





All Articles