一般应用隐私协议都是通过H5页面加载的,跳转空白页面时,首先查看链接是否有效。搜索该应用的隐私协议发现,邮箱地址是一个a标签,且采用了mailto协议。
<!DOCTYPE html>
<html>
<body>
<div>
<a href="mailto:xx.xx.xx" style="font-size: 40px;">xx.xx.xx</a>
</div>
</body>
</html> 而Web组件是不支持通过mailto协议拉起邮箱应用的,因此把该链接识别为了无效链接,所以跳转到空白页面。
应用需要自己通过onLoadIntercept回调拦截“mailto”协议链接跳转,调用API拉起对应服务,相关介绍详见跨应用跳转。
import { webview } from '@kit.ArkWeb'; import { common, Want } from '@kit.AbilityKit'; @Entry @Component struct Index { private webviewController: webview.WebviewController = new webview.WebviewController(); build() { Column() { Web({ src: $rawfile('testMail.html'), controller: this.webviewController }) .geolocationAccess(false) .fileAccess(false) .size({ width: '100%' }) .onLoadIntercept((event) => { if (event) { let url: string = event.data.getRequestUrl(); // 判断链接是否mailto if (url.indexOf('mailto:') === 0) { // 拉起邮件应用 let context = this.getUIContext().getHostContext() as common.UIAbilityContext; let want: Want = { // 以系统自带邮件为例,实际请自行替换 bundleName: 'com.huawei.hmos.email', abilityName: 'EntryAbility', // uri里面通过mailto来配置收件人邮箱等参数。数据仅做示例,实际请替换为需要内容 uri: 'mailto:123@***.com,456@***.com?subject=我是邮件标题&body=我是正文内容&&cc=cc@***.com&&bcc=bcc@***.com&&sceneType=2', }; context.startAbility(want).then((data) => { console.info(`Success, ${data}`); }).catch(() => { console.error('error'); }); return true; } } return false; }); } .height('100%') .width('100%'); } }
详细方案介绍可参考:拉起邮件类应用(mailto方式)。