鸿蒙HarmonyOS实战-Web组件(前端函数和应用侧函数相互调用)
harmonyos,web
·
浏览次数 : 0
小编点评
**JavaScript To Window**
```javascript
('Register JavaScript To Window') .onClick(() => { try { this.webviewController.registerJavaScriptProxy(this.testObj, \"testObjName\", [\"test\", \"test\"]); } catch (error) { let e: business_error.BusinessError = error as business_error.BusinessError; console.error(`ErrorCode: ${e.code}, Message: ${e.message}`); } }) Web({ src: $rawfile('local.html'), controller: this.webviewController }) } }}🔎3.建立应用侧与前端页面数据通道🦋3.1 前端页面<!--xxx.html--><!DOCTYPE html><html><head> <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"> <title>WebView Message Port Demo</title></head><body> <h1>WebView Message Port Demo</h1> <div> <input type=\"button\" value=\"SendToEts\" onclick=\"PostMsgToEts(msgFromJS.value);\"/><br/> <input id=\"msgFromJS\" type=\"text\" value=\"send this message from HTML to ets\"/><br/> </div> <p class="output" >display received message send from ets</p></body>&