页面类似弹框样式跳转H5

现在有一个场景,我从A页面跳转到B页面,我的B页面其实是个H5,且不是全屏,我需要看到A页面的内容,相当于Dialog。解释一下,这里为什么不用CustomDialog,因为按照文档说明,CustomDialog需要绑定页面,而我这里的场景,我这个登录是第三方的库,用CustomDialog对接入方来说不便捷。

HarmonyOS
2024-11-07 09:56:28
691浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zbw_apple

​可以使用subWindow的方式弹窗,参考:​https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/application-window-stage-V5#设置应用子窗口

示例代码:​

@Entry 
@Component 
struct Index { 
  webController: webview.WebviewController = new webview.WebviewController(); 
  aboutToAppear(): void { 
    webview.WebviewController.setWebDebuggingAccess(true) 
    const windowStage: window.WindowStage | undefined = AppStorage.get("windowStage") 
    if (windowStage) { 
      windowStage.createSubWindow('test', (err, win) => { 
        if (err.code) { 
          console.log(JSON.stringify(err.code)) 
        } else { 
          win.loadContentByName(entryName); 
          win.resize(500, 500); 
          win.moveWindowTo(500, 500) 
          win.showWindow(); 
        } 
      }) 
    } 
  } 
 
  build() { 
    Row() { 
      Column() { 
        Text('Index') 
          .fontSize(50) 
          .fontWeight(FontWeight.Bold) 
      } 
      .width('100%') 
    } 
    .height('100%') 
 
  } 
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.

Page3:

export const entryName: string = 'Page3'; 
@Entry({ routeName: entryName }) 
@Component 
struct Page3 { 
  @State message: string = 'Hello World'; 
  webController: webview.WebviewController = new webview.WebviewController(); 
 
  build() { 
    Row() { 
      Column() { 
        Web({ src:'https://xxx.huawei.com',controller:this.webController }) 
          .domStorageAccess(true) 
          .onTitleReceive(event => { 
            if (event?.title) { 
              console.log('receive title: ----- ' + event.title) 
            } else { 
              console.log('receive title not found ') 
            } 
          }) 
      } 
      .width('100%') 
    } 
    .height('100%') 
    .backgroundColor(Color.Red) 
  } 
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
分享
微博
QQ
微信
回复
2024-11-07 17:31:48


相关问题
HarmonyOS 类似h5中qs.stringify
516浏览 • 1回复 待解决
HarmonyOS webview h5跳转到应用
702浏览 • 1回复 待解决
半模态转场来实现样式页面
1610浏览 • 1回复 待解决
H5页面输入自动获焦弹起软键盘
2624浏览 • 1回复 待解决
HarmonyOS h5页面缩放问题
1903浏览 • 1回复 待解决
H5页面如何与ArkTS交互
4016浏览 • 1回复 待解决
HarmonyOS H5页面localstorage为null
884浏览 • 1回复 待解决
HarmonyOS webview H5页面事件监听
1226浏览 • 1回复 待解决
HarmonyOS h5原生交互、页面状态机
734浏览 • 1回复 待解决
HarmonyOS 在H5中如何跳转到应用市场
1639浏览 • 1回复 待解决
HarmonyOS web组件加载h5h5拉起摄像头
1499浏览 • 1回复 待解决
HarmonyOS 原生和H5页面交互
674浏览 • 1回复 待解决
HarmonyOS H5页面加载缓存机制
1241浏览 • 1回复 待解决
恭喜您,今日已阅读两篇内容,特奖励+2声望, 快来领取吧。