1.1K Star 6.1K Fork 5K

OpenHarmony / docs

 / 详情

@ohos.web.webview.WebviewController loadData支持加载含特殊字符的网页字符串, 例如#

待办的
需求
创建于  
2023-04-26 17:04

【需求价值】:
loadData可用来加载html字符串,使用中含有特殊字符的字符串无法加载
【需求描述】:
loadData支持加载含特殊字符的网页字符串
【方案描述】:

import webview from '@ohos.web.webview'

@Entry
@Component
struct WebComponent {
  controller: web_webview.WebviewController = new webview.WebviewController();
  updataContent: string = '<body><div><image src=file:///data/storage/el1/bundle/entry/resources/rawfile/xxx.png alt="image -- end" width="500" height="250"></image></div></body>'

  build() {
    Column() {
      Button('loadData')
        .onClick(() => {
          try {
            this.controller.loadData(this.updataContent, "text/html", "UTF-8", " ", " ");
          } catch (error) {
            console.error(`ErrorCode: ${error.code},  Message: ${error.message}`);
          }
        })
      Web({ src: 'www.example.com', controller: this.controller })
    }
  }
}

上述代码可成功加载,但是如果在updataContent中添加#则显示空白,例如updataContent = '<body><div><image src=file:///data/storage/el1/bundle/entry/resources/rawfile/xxx.png# alt="image -- end" width="500" height="250"></image></div></body>'

推测原因仅对updataContent做encodeURI,该方法不会对#进行编码
this.controller.loadData(this.updataContent, "text/html", "UTF-8", " ", " ");改成this.controller.loadData(encodeURIComponent(this.updataContent), "text/html", "UTF-8", " ", " ");则加载正常,改成this.controller.loadData(encodeURI(this.updataContent), "text/html", "UTF-8", " ", " ");显示空白

【配套文档】:

【验收标准】:
loadData支持加载含特殊字符的网页字符串

评论 (0)

Sakura 创建了需求
Sakura 修改了描述
Sakura 修改了描述
Mei 负责人设置为luoying_ace
NEEN 负责人luoying_ace 修改为未设置
NEEN 负责人设置为bigpumpkin
展开全部操作日志

登录 后才可以发表评论

状态
负责人
项目
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
预计工期 (小时)
参与者(1)
其他
1
https://gitee.com/openharmony/docs.git
git@gitee.com:openharmony/docs.git
openharmony
docs
docs

搜索帮助