我想要做的是看看我的网站的标签是否在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');
}
}
})
);
});发布于 2015-09-10 15:22:31
看起来client.navigate()还没有实现(截至2015年9月10日),甚至在Canary中也没有。几个月前才具体说明的。,2015年6月。这是特征状态页和相关的铬票。一旦实现了navigate(),您的代码可能就能工作。
https://stackoverflow.com/questions/32504823
复制相似问题