通过onLoadIntercept拦截接口可以根据业务做相应处理。import web_webview from '@ohos.web.webview'; import { common, Want } from '@kit.AbilityKit'; @Entry @Component struct WebComponent { webviewController: web_webview.WebviewController = new web_webview.WebviewController(); build() { Column() { Web({ src: $rawfile('local.html'), controller: this.webviewController}) .onLoadIntercept((event) => { if (event) { let url: string = event.data.getRequestUrl(); if (url.indexOf('store://') === 0) { const want: Want = { uri: `store://appgallery.huawei.com/` } const context = getContext(this) as common.UIAbilityContext; context.startAbility(want).then(() => { }).catch(() => { }) return true; } } return false; }) } } }<!-- local.html --> <!DOCTYPE html> <html> <body> <p>Hello World</p> <br><a>P3-</a><a href="store://appgallery.huawei.com/">应用市场</a></div> </body> </html>
通过onLoadIntercept拦截接口可以根据业务做相应处理。