Chrome Desktop notification to all users

偶尔善良 提交于 2019-12-25 20:05:12

问题


I have tried to add Chrome Desktop notification to my website. I have followed this:

Chrome desktop notification example

and I have added the script code to my website and it work fine with me, but I have a problem.

When I click on "notify" button the notification just appears to me, but I want the notification be shown to all users who granted the permission.

Can anyone help me please?


回答1:


You're looking at wrong documentation - or rather, only one part of it. There are separate problems of displaying the notification (which you solved) and delivering it to others (which you didn't, and alarmingly didn't understand that it's missing).

You have to code the show a local notification, but there's nothing to actually send out (push) the message or receive it. In short, there's still a lot of work to be done.

What you need is the Push API. It involves creating a Service Worker for your site (which will be the part able to listen to push messages) and having server-side code that talks to Google Cloud Messaging to generate a push. There's a good tutorial on how to use it.



来源:https://stackoverflow.com/questions/35655817/chrome-desktop-notification-to-all-users

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!