admin管理员组文章数量:1279247
So lately on some websites I have seen these browser level invoked notifications that popup even if you didn't open that certain website. You have to allow those notifications to be displayed and then they are pretty much everywhere, even when you first open a browser without tabs.
I don't know how to use for these browser level notifications invoked by my website. A name and some code examples would be appreciated, I don't even know what programming language it's written in (assuming Javascript).
This is a screenshot of what I'm talking about (top right corner):
As you see, they still appear even though the browser is minimized!
So lately on some websites I have seen these browser level invoked notifications that popup even if you didn't open that certain website. You have to allow those notifications to be displayed and then they are pretty much everywhere, even when you first open a browser without tabs.
I don't know how to use for these browser level notifications invoked by my website. A name and some code examples would be appreciated, I don't even know what programming language it's written in (assuming Javascript).
This is a screenshot of what I'm talking about (top right corner):
As you see, they still appear even though the browser is minimized!
Share Improve this question edited Jun 30, 2015 at 7:15 aborted asked Jun 30, 2015 at 7:04 abortedaborted 4,54114 gold badges73 silver badges134 bronze badges3 Answers
Reset to default 12 +25These are implemented using the Notification API - some recent documentation can be found here:
https://developer.mozilla/en-US/docs/Web/API/notification
You can easily try it from the console of most current browsers -
Notification.requestPermission();
Approve the notification permission and then try
new Notification('Hello, you have been notified!');
The documentation has more detailed usage examples.
As pvg said, there is a Browser API named Notification
, which allows you to send notifications to your users. You must request permission first, and if granted
, build a new Notification
.
I have built a micro library in javascript that does exactl that as an object, go check it out here: https://github./jsmrcaga/miniNotif
Usage is simple, you make a new notification as an object like so:
var yourNotif = new miniNotif.notification('title', {body: 'your body', icon: 'URL'});
, and call yourNotif.show()
whenever you want it to be displayed.
I believe that the readme on GitHub is out of date though
If you want to implement normal notifications, the answers that you have received are all correct.
If you want to implement PUSH notifications, the answer you expect is in this post (with explanation and a tutorial explaining how you can implement it).
本文标签: javascriptBrowser notifications invoked websiteStack Overflow
版权声明:本文标题:javascript - Browser notifications invoked website - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741234316a2362701.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论