简体   繁体   English

将webview的内容设置为html字符串(cocoa)

[英]Set contents of webview to html string (cocoa)

Is there any easy way to set the contents of a webview to an HTML string (without having to load a file)? 有没有简单的方法将webview的内容设置为HTML字符串(无需加载文件)?

Thanks 谢谢

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

(其中someURL用于解析HTML源中的相对URL。)

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

如果你想加载资源目录中的样式表(css)或javascripts(js)文件,你可以使用[[NSBundle mainBundle] bundleURL] ,如果不是,只需使用nil

是的,肯定在webView的mainFrame上调用loadHTMLString:baseURL:就可以了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM