import web_webview from ‘@ohos.web.webview’; import call from ‘@ohos.telephony.call’; import { BusinessError } from ‘@ohos.base’; @Entry @Component struct WebComponent { webviewController: web_webview.WebviewController = new web_webview.WebviewController(); build() { Column() { Web({ src: $rawfile(‘call.html’), controller: this.webviewController}) .onLoadIntercept((event) => { if (event) { let url: string = event.data.getRequestUrl(); // 判断链接是否为拨号链接 if (url.indexOf(‘tel://’) === 0) { call.makeCall(url.substring(6),(err: BusinessError) => { if (!err) { console.log(“make call success.”); } else { console.log(“make call fail, err is:” + JSON.stringify(err)); } }); return true; } } return false; }) } } }call.html:<!DOCTYPE html\> <html\> <body\> <div\> <a href="tel://10086"\>拨打电话</a\> </div\> </body\> </html\>
call.html: