小编Bol*_*ipo的帖子

单击@ angular/service-worker推送通知的操作部分

我一直在尝试将用户重定向到来自后端(PHP)的Webpush的"动作"部分.

    return (new WebPushMessage)
        ->title('Title')
        ->icon('icon.png')
        ->body('Body Msg')
        ->action('Open Notification', 'open_notification')
        ->data(['id' => $notification->id,'url'=>'http://somewhere']);
Run Code Online (Sandbox Code Playgroud)

默认服务工作者使用:

self.addEventListener('notificationclick', function(event) {
    console.log('On notification click: ', event.notification.tag);
    event.notification.close();

    // This looks to see if the current is already open and
    // focuses if it is
    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('/');
    }));
});
Run Code Online (Sandbox Code Playgroud)

来自https://developer.mozilla.org/en-US/docs/Web/Events/notificationclick

Angular …

angular5

5
推荐指数
1
解决办法
1726
查看次数

标签 统计

angular5 ×1