背景:
当前应用中有一个嵌套的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')
})