Web页面的显示过程可以被分为多个阶段,包括DNS解析、建立连接、发送请求、接收响应、解析HTML、下载资源等步骤
import { webview } from '@kit.ArkWeb';
@Entry @Component struct Hybrid { @State message: string = 'Hello World'; webController:webview.WebviewController = new webview.WebviewController() build() { Column(){ Button('modify') .onClick(()=>{ this.webController.registerJavaScriptProxy(new Inject(),"test",["getLocation"]) this.webController.refresh() }) Web({src:$rawfile("web.html"),controller:this.webController}) } .height('100%') .width('100%') } }
class Inject{ getLocation(){ AlertDialog.show({message:"Hello"}) } }
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <h1>这是标题</h1> <button onclick="getLocation()">获取位置信息</button> <script> function getLocation(){ test.getLocation() } </script> </body> </html>
|