鸿蒙web组件中跳转其他页面

背景:

当前应用中有一个嵌套的h5页面,使用web组件挂载以后,h5页面中的跳转微信等页面不会进行跳转还会导致页面卡死

解决方案:

需要配置onWindowNew事件,否则不会跳转,他的作用就是使能multiWindowAccess情况下,通知用户新建窗口请求,这样就可以跳转;

  .allowWindowOpenMethod(true)
          // 浏览器打开h5里的东西
          .onWindowNew((event) => {
            event.handler.setWebController(null)
            let context = getContext(this) as common.UIAbilityContext;
            let wantInfo: Want = {
              action: 'ohos.want.action.viewData',
              // entities can be omitted.
              entities: ['entity.system.browsable'],
              uri: event.targetUrl
            }
            context.startAbility(wantInfo)
          })
完整代码:
 Web({ src: this.src, controller: this.webviewController })
          .fileAccess(true)//开启应用中文件系统的访问,默认启用
          .multiWindowAccess(true)
          .domStorageAccess(true)
          .height('100%')
          .width('100%')
          .allowWindowOpenMethod(true)
          // 浏览器打开h5里的东西
          .onWindowNew((event) => {
            event.handler.setWebController(null)
            let context = getContext(this) as common.UIAbilityContext;
            let wantInfo: Want = {
              action: 'ohos.want.action.viewData',
              // entities can be omitted.
              entities: ['entity.system.browsable'],
              uri: event.targetUrl
            }
            context.startAbility(wantInfo)
          })
          .onShowFileSelector((event) => {
            if (event) {
              this.selectFile(event.result);
            }
            return true;
          })
          .onPageEnd(()=>{
            this.dialogController.close()
            emitter.emit('lodingClose')
          })

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值