3

I found the documentation for chrome apps rich notifications.
Is it possible (after getting the right permissions) to use these notifications in a regular web page?
If not, is there any other type of desktop notification that is possible in chrome?
Maybe something like gmail has been doing for a long time?

Ron Harlev
  • 16,227
  • 24
  • 89
  • 132
  • 1
    That would be [chrome desktop notifications](http://www.chromium.org/developers/design-documents/desktop-notifications/api-specification) also see http://stackoverflow.com/questions/2271156/chrome-desktop-notification-example – Kerry Liu Sep 22 '13 at 17:43

2 Answers2

4

So you need something like this?

Try it!

<script>
function notify() {
  var havePermission = window.webkitNotifications.checkPermission();
  if (havePermission == 0) {
    // 0 is PERMISSION_ALLOWED
    var notification = window.webkitNotifications.createNotification(
      'http://test.didacticmedia.ro/img/didactic.png',
      'Notification test!',
    'details text'
    );

    notification.onclick = function () {
      window.open("http://stackoverflow.com/questions/18414462/chrome-rich-notifications-in-normal-web-pages/19031405#19031405");
      notification.close();
    }
    notification.show();
  } else {
      window.webkitNotifications.requestPermission();
  }
}  
</script>

<div style="width: 100px; height: 100px; background: red" onclick="notify()">
Click here!
</div>
Acelasi Eu
  • 914
  • 2
  • 9
  • 30
0

Rich notifications appear to be unavailable in regular web pages. I'm basing this on the fact that they use chrome.notifications, which is undefined in normal Chrome browser windows. (If there's a workaround, I'd like to know).

You can use the regular Notification object, which seems to be a new standard, although it's far from "rich" and it doesn't behave the same in all browsers. For example, in Chrome a notification stays up until the user dismisses it, whereas in Firefox it only stays on the screen for a few seconds.

aldel
  • 6,489
  • 1
  • 27
  • 32