Question

Is there any easy way to set the contents of a webview to an HTML string (without having to load a file)?

Thanks

Was it helpful?

Solution

[[webView mainFrame] loadHTMLString:htmlString baseURL:someURL];

(Where someURL is used to resolve relative URLs in the HTML source.)

OTHER TIPS

[webView loadHTMLString:yourString baseURL:[[NSBundle mainBundle] bundleURL]];

You can use [[NSBundle mainBundle] bundleURL] if you desire to load stylesheets(css) or javascripts(js) files that are in your resources dir, if not, just use nil

Yes definitely calling loadHTMLString:baseURL: on the mainFrame of the webView would do it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top