1
我想要做的是查看我的網站的某個標籤是否在Chrome中打開,如果是這樣,請將其關注並轉發給我傳遞的新網址通過。ServiceWorker Chrome推送通知 - 轉發到新頁面
作爲參考,當你看到「event.notification.data」這將是一個鏈接,如「https://www.example.com/mobile/profile.php?id=Webmaster」
我可以將精力集中在選項卡上,但我不能作出這樣的標籤重定向到URL我已經存儲在「event.notification.data」
這裏是我的代碼
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');
}
}
})
);
});
我讀了很多這些,但我想我不想相信它。謝謝您的幫助。 – dbye
您也可以進入檢查員併爲自己進行驗證。我在Canary中通過獲取客戶端對象並在'__proto__'屬性中看到它有'focus()'方法但沒有'navigate()'方法來檢查它。 –