javascript - 如何专注于标签,在Angular 8中点击通知?
问题描述
目标是当用户点击浏览器通知时,查看页面是否已经打开并转到它,如果没有,则在新选项卡或窗口中打开它。
使用此代码使用本机服务人员时,这是可行的
const promiseChain = clients.matchAll({
type: 'window',
includeUncontrolled: true }) .then((windowClients) => {
let matchingClient = null;
for (let i = 0; i < windowClients.length; i++) {
const windowClient = windowClients[i];
if (windowClient.url === urlToOpen) {
matchingClient = windowClient;
break;
}
}
if (matchingClient) {
return matchingClient.focus();
} else {
return clients.openWindow(urlToOpen);
} });
event.waitUntil(promiseChain);
但是在角度上,他们有自己的服务工作者包装器,它会在运行时生成服务工作者文件。
我现在的角度代码是这样的
this.swPush.notificationClicks.subscribe(
({ action, notification }) => {
if (notification && notification !== null && notification['data']) {
const url = notification['data'].url;
window.open(url, '_blank');
}
});
那么首先有没有办法在角度(swPush)中实现这个?
如果不是,我是否必须编辑生成的服务工作者文件,以及如何(最佳实践)?或者我可以导入另一个服务工作者文件吗?
解决方案
推荐阅读
- docker - NGINX 反向代理未将请求主机名转发到 docker 容器
- php - PHP - 加入相等的数组并添加加入的数组计数
- android - 使用 args 'stereo:c0 初始化过滤器 'pan' 时出错
我在 FFmpeg 命令下运行以合并音频和视频,使用 FFmpeg 4.0-39 版本保留视频的原始音频-
-i /storage/emulated/0/Movies/extract_audio.mp3 -i /storage/emulated/0/Movies/VID-20200501-WA0000.mp4 -filt
- java - 用户制作的链表类将对象存储在具有菜单功能的文本文件中
- python - 天蓝色函数 python - Blob 触发器和超时
- javascript - Javascript 功能默认关闭
- javascript - 如何下载带有标签的外部 .VTT
- c - 在 C 中出错:从不兼容的指针类型传递函数的参数 1
- node.js - 如何在Vue中导入和使用P5.Sound?
- c++ - 代理模型和按钮问题