September 23rd, 2009, by alex

How to get the contents of UIWebView on iPhone

Say you have a UIWebView in your iPhone application, maybe you have some JavaScript that changes its content, for whatever reason you want to access the content of the UIWebView… how do you do it?

It’s not immediately obvious from the API docs, but it’s pretty simple. Something like this should do the trick:

[myWebView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('html')[0].innerHTML"]

Doesn’t seem all that clean, but it’s the best I’ve found so far - if there’s a better way, I’d love to know.

One comment so far Subscribe Comments

  1. Dude… you rule.


Add your comment