3

I am working with a UIWebview, is there anyway I can just load just the body of a webpage instead of the entire webpage with my UIWebView (aka not load the header and footer)? This website is not mine. But looking at the HTML of this site, I only want to load to div id="mainContent" to /div Either by writing some objective c or javascript?

Thanks! Alan

Alan
  • 9,331
  • 14
  • 52
  • 97

1 Answers1

3

With Web-Kit you can parse the incoming HTML and do whatever you like to it (within, legal rights to the site you are reading)

Once the data is loaded in you can then push the edited HTML to the WKView fairly easily.

If you have an outlet to the webView you can do: (For example a UIWebView in iOS)

[webView loadHTMLString:htmlString baseURL:nil];
[webView setNeedsDisplay];
Dru Freeman
  • 1,766
  • 3
  • 19
  • 41
  • 1
    Thank you for that. Could you give me an example on how to do this? The webView has a page loaded and i want to remove the
    how does one do that?
    – Alan Mar 20 '12 at 02:57
  • Actually I just tried to do this, but it doesn't keep any of the formatting. When I load it up, it is showing some of the text with no formatting. – Alan Mar 20 '12 at 04:01
  • It's up to you to make sure your HTML contains either the embedded CSS or the base URL is set to point to somewhere that the meta info in the can find other files. – Dru Freeman Mar 21 '12 at 03:09