中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
微信扫码分享
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no,viewport-fit=cover"> <title> </title> <script> function openWindow() { window.myJsb.openDialog() } </script> </head> <body> <button onclick="openWindow()" style="width: 200px;height: 200px"> 前端调用JSB打开窗口 </button> </body> </html> import webview from '@ohos.web.webview' export interface JsbObject { openDialog: () => void } @Entry() @Component struct Page2 { webviewController = new webview.WebviewController() dialogController: CustomDialogController = new CustomDialogController({ builder: CustomDialogExample({}) }) jsbObject: JsbObject = { openDialog: () => { this.showDialog(this) } } showDialog(context: object) { // 怎么把自定义弹窗调出来 this.dialogController.open() } build() { Column() { Web({ src: "resource://rawfile/aa.html", controller: this.webviewController }) .javaScriptAccess(true) .javaScriptProxy({ name: "myJsb", object: this.jsbObject, methodList: ["openDialog"], controller: this.webviewController }).width('100%') } .backgroundColor(Color.Brown) } } @CustomDialog struct CustomDialogExample { dialogControllerTwo: CustomDialogController | null = new CustomDialogController({ builder: CustomDialogExample(), alignment: DialogAlignment.Bottom, offset: { dx: 0, dy: -25 } }) controller?: CustomDialogController build() { Row() { Text("自定义键盘") }.height('40%') } }