gpt4 book ai didi

javascript - 服务人员: Redirecting a user to different url when he clicks the notification

转载 作者:行者123 更新时间:2023-11-28 13:14:49 24 4
gpt4 key购买 nike

此代码片段有助于将应用程序选项卡置于焦点或使用该 URL 打开新选项卡。如果选项卡已打开,是否可以更改 URL(基于用户单击的通知)。?

  event.waitUntil(
clients.matchAll({
type: 'window'
})
.then(function(windowClients) {
for (var i = 0; i < windowClients.length; i++) {
var client = windowClients[i];
if (url.test(client.url) && 'focus' in client) {
return client.focus();
}
}
if (clients.openWindow) {
return clients.openWindow('/#/chat');
}
})
);

最佳答案

WindowClient.navigate()方法听起来像你想要的。您应该能够执行以下操作:

// Assume that you want to find the first window that is currently open
// to originalUrl, and navigate that window to navigationUrl.
// If there is no window currently at originalUrl, then open a new window.
event.waitUntil(
clients.matchAll({type: 'window'})
.then(clients => clients.filter(client => client.url === originalUrl))
.then(matchingClients => {
if (matchingClients[0]) {
return matchingClients[0].navigate(navigationUrl)
.then(client => client.focus());
}

return clients.openWindow(navigationUrl);
})
);

关于javascript - 服务人员: Redirecting a user to different url when he clicks the notification,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39476963/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com