Last Updated: February 25, 2016
·
2.747K
· killme2008

Chrome notification

var notification = webkitNotifications.createNotification(
                'icon.png',
                'title',
                'text"
);
notification.show();
   //cancel it after 5 seconds.
setTimeout(function(){
    notification.cancel();
},5000);

In manifest.json:

"permissions": [
    "notifications"
 ],
"web_accessible_resources": [
   "icon.png"
 ]

2 Responses
Add your response

Worth saying that this could also be used in webpages, you'll need to add permission handling with: window.webkitNotifications.checkPermission() and window.webkitNotifications.requestPermission().

Note: You must try this using a server request (it won't work with a file:// URL )

A complete example can be found here: http://www.html5rocks.com/en/tutorials/notifications/quick/

regards!

over 1 year ago ·

Yes,i've read your post before,thanks.

over 1 year ago ·

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside