我要做的是查看我网站的标签是否在 Chrome 中打开,如果是,请关注它并将它们转发到我正在通过的新 URL。
作为参考,当您看到“event.notification.data”时,它将是一个链接,例如“ https://www.example.com/mobile/profile.php?id=Webmaster ”
我可以专注于选项卡,但我无法使该选项卡重定向到我存储在“event.notification.data”中的 URL
这是我的代码
self.addEventListener('notificationclick', function(event) {
event.notification.close();
event.waitUntil(
clients.matchAll({
type: "window"
})
.then(function(clientList) {
// loop through all the tabs
for (var i = 0; i < clientList.length; i++) {
var client = clientList[i];
//check if a tab starts with the websites name
if (client.url.indexOf("https://www.example.com/mobile") == 0 && 'focus' in client){
//a tab matched! Check if the data (a link) is there
//------
//THIS IS WHERE I NEED HELP
//------
if(event.notification.data != ''){
//yes! event.notification.data is a link, focus on the tab and forward them there
client.focus();
client.navigate(event.notification.data);
} else {
//no! event.notification.data was blank, focus on the tab and forward them to the general site
client.focus();
client.navigate('https://www.example.com/mobile');
}
}
}
if (clients.openWindow) {
if(event.notification.data != ''){
clients.openWindow(event.notification.data);
} else {
clients.openWindow('https://www.heftynet.com/mobile');
}
}
})
);
});