#鸿蒙通关秘籍#如何正确获取Web组件的广告过滤结果?

HarmonyOS
2024-12-16 12:46:44
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
DataDiver

在开启广告过滤后,可以通过Web组件提供的 onAdsBlocked() 回调接口接收过滤结果。此接口会收集并通知过滤掉的广告详细信息。

typescript import { webview } from '@kit.ArkWeb';

@Entry @Component struct WebComponent { @State totalAdsBlockCounts: number = 0; controller: webview.WebviewController = new webview.WebviewController();

build() { Column() { Web({ src: 'https://www.example.com', controller: this.controller }) .onAdsBlocked((details) => { if (details) { console.log('Blocked ' + details.adsBlocked.length + ' in ' + details.url); this.totalAdsBlockCounts += details.adsBlocked.length; console.log('Total blocked counts: ' + this.totalAdsBlockCounts); } }); } } }

分享
微博
QQ
微信
回复
2024-12-16 15:53:49
相关问题
如何过滤textinput组件内容
810浏览 • 1回复 待解决