单击推送通知后,防止重定向到站点的根目录

时间:2015-05-27 11:59:14

标签: service-worker web-push

在chrome上使用服务工作者进行推送通知时,我们会向用户显示推送通知。点击通知通常会将浏览器打开到网站原点的根目录。

在以下事件的回调中:

self.addEventListener('notificationclick', function(event) {})

尝试更改' /'的窗口位置网址。到' / redirectpage':

event.waitUntil(clients.matchAll({
type: "window"}).then(function(clientList) {
for (var i = 0; i < clientList.length; i++) {
  var client = clientList[i];
  if (client.url == '/' && 'focus' in client){
      return client.focus();
  }
}
if (clients.openWindow){
    //return clients.openWindow('/');
    return clients.openWindow('/redirectpage');//changed above code to this
}
}));

所以预期结果,我们在localhost上说应该是http://localhost:8080/redirectpage。但是,点击通知仍然会将我重定向到网站的来源http://localhost:8080

假设这是错误的方法,我需要在哪里指定目标网址,以便浏览器在点击推送通知时打开此目标网址?

0 个答案:

没有答案