【关键字】
Web组件 / 加载富文本
【问题描述】
Web组件通过WebviewController.loadData方法加载含有color: #000000样式的HTML文本时,出现页面无法加载的现象。
【解决方案】
HTML中的富文本中带有注入#等特殊字符,建议使用带有两个空格的loadData函数,将baseUrl和historyUrl设置为空,因为两个函数解析方式不一样,没有两个空格的函数解析不了css 中的"#" 比如 color:#000000。
loadData(data: string, mimeType: string, encoding: string, baseUrl?: string, historyUrl?: string): void
这个接口中请给baseUrl或historyUrl任一参数赋值空格。
参考官网示例修改一下:
this.webviewController.loadData(richText, "text/html", "UTF-8");
修改为
this.webviewController.loadData(richText,"text/html","UTF-8"," ", " ");