HarmonyOS webview h5跳转到应用?

如题:HarmonyOS webview h5跳转到应用?

阅读 492
1 个回答

以下demo是h5跳转到应用详情

import web_webview from '@ohos.web.webview';
import { common, Want } from '@kit.AbilityKit';
class NaviAppStore {
  constructor() {
  }

  jumpAgcDetailPage() {

    const want: Want = { uri: `store://appgallery.huawei.com/`
      //uri: `store://appgallery.huawei.com/` //跳转拉起应用市场APP首页
    }
    const context = getContext(this) as common.UIAbilityContext;
    context.startAbility(want).then(() => {
      console.log('jumpAgcDetailPage 拉起成功');
    }).catch(() => { console.log('jumpAgcDetailPage 拉起失败');
    })
  }
}
@Entry
@Component
struct WebPage {
  controller: web_webview.WebviewController = new web_webview.WebviewController()
  @State naviApp:NaviAppStore = new NaviAppStore()
  build() {
    Row() {
      Column() {
        Web({ src: $rawfile("go_to_agc_unipay.html"), controller: this.controller })
          .javaScriptProxy({ object: this.naviApp, name: "naviApp", methodList: ["jumpAgcDetailPage"], controller: this.controller }) }
      .width('100%')
    }
    .height('100%')
  }
}

//go_to_agc_unipay.html
<!DOCTYPE html>
  <html>
  <body>
  <button type="button" onclick="callArkTS()">Click Me!</button>
  <p id="demo"></p>
  <script>
  function callArkTS() {
    let str = naviApp.jumpAgcDetailPage();
  }
  </script>
  </body>
  </html>
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进