WebKit: load HTML content as string?

retrotron

thinking is design
Is there any way to pass some HTML content as a stream to a WebKit view to be rendered? Something like this:

[[webView mainFrame] initWithHTML: @"<html>Hello world!</html>"];
 
Hehe no offense but did you attempt to even glance at the documentation? ;)

Try something like this:
Code:
[[webView mainFrame] loadHTMLString:@"<html>Hello world!</html>" baseURL:nil]
 
Heh heh, yeah, I checked the doc and thought it said the loadHTMLString method takes the String as the URL (easier than using an NSURL object).
 
Just to clarify my response above. Yes, the method loadHTMLString:baseURL: works to load HTML code and have it rendered in the WebView.

My cryptic comment above meant to say that I assumed from the doc that the String in question was the filename of the page (with baseURL setting the base URL), not the content of the page. The doc says:

Sets the string to use for the main page of the document to string, and the base URL to URL.The base URL allows relative URLs within a document.

which makes no sense to me whatsoever. I don't understand the 'string to use for the main page of the document to string' sentence at all, and I'm not sure why a base URL has anything to do with this method, if you just use it to load an HTML content string. Anybody want to offer some insight?
 
I think the base URL is so if there are any relative URLs in the page, it has a "base URL" to complete the URL.
 
Hmmm...so normally the browser chooses the page's current URL as the base URL to complete relative URLs, but in this case there is no current URL since the HTML content is loaded not from a URL but a string, so here you provide the base URL. Is that how this is working?

<edit>Yep, I just tried it. That's what it does. Thanks all. I must be the only person who finds apple doc unintelligible most of the time. ;)</edit>
 
Back
Top