HarmonyOS web和js交互的时候只能点击触发交互,没有办法进入就交互?

如题:HarmonyOS web和js交互的时候只能点击触发交互,没有办法进入就交互?

阅读 467
1 个回答

用下面这种形式javaScriptProxy,在进入的时候,可以调用注册的方法。参考文档: https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-basic-components-web-V5\#javascriptproxy

完整demo:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/web-in-page-app-function-invoking-V5

Web({src: $rawfile('index.html'), controller: this.controller})
  .domStorageAccess(true)
  .javaScriptProxy({
    object: this.testObj,
    name: "testObjName",
    methodList: ["test", 'setData'],
    controller: this.controller
  })
<!-- index.html -->
  <!DOCTYPE html>
  <html>
  <body>
  <div style="font-size:40px">
  名称:<input id="nameInput" type="text">
  <br/>
  <br/>
  年龄:<input id="ageInput" type="text">
  <br/>
  <br/>
  <button type="button" onclick="callArkTS111()">提交</button>
  <p id="demo"></p>
  </div>
  <script>
  console.log('############Start Init', testObjName.test());
</script>
  </body>
  </html>
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进