Saving HTML from WebView to existing file in Documents Directory

420 Views Asked by At

I have been working on some code that loads and saves HTML files. I have been able to create them, but after they are edited in the WebView, I need to save an HTML file from the webView back to the documents directory. I am not sure how to create the HTML file however. I would appreciate your help. I have the document file path and title.

1

There are 1 best solutions below

1
On BEST ANSWER

The only way I can think of doing this is with javascript to pull out the html. For example if you have a reference to your UIWebView object called webView the following would return a string containing the inner html:

[bodyView stringByEvaluatingJavaScriptFromString:@"document.body.innerHTML"]);

You could then dress it back up to a complete html page, the javascript will only return the content within the <body> tags. Presumably within your code that loads and then edits the html page you can know, and therefore store, any specific information that occurred outside of the <body> tags such that you can restore it?