HarmonyOS H5页面控制按钮是否显示?

如题:HarmonyOS H5页面控制按钮是否显示?

阅读 497
1 个回答

参考demo:

import { webview } from '@kit.ArkWeb';

@Entry
@Component
struct WebComponent {
  controller: webview.WebviewController = new webview.WebviewController();
  @State flag:boolean = true
  build() {
    Column() {
      if (this.flag) {
        Text('显示')
      }
      Web({ src: $rawfile('index5.html'), controller: this.controller })
        .javaScriptAccess(true)
        .domStorageAccess(true)
        .onLoadIntercept((event) => {
          if (event.data.getRequestUrl() === 'xxx') {
            this.flag = false
          } else {
            this.flag = true
          }
          return false;
        })
    }.height('100%').width('100%')
  }
}
<!DOCTYPE html>
  <html lang="zh-CN">
  <head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  </head>
  <body>
  <button id="init" onclick="jump()">跳转</button>
  </body>
  </html>
  <script>
  function jump() {
    window.location.href = 'xxx'
  }
  </script>
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进