html5notification.js 955 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. [Discuz!] (C)2001-2099 Comsenz Inc.
  3. This is NOT a freeware, use is subject to license terms
  4. $Id: html5notification.js 31484 2012-09-03 03:49:21Z zhangjie $
  5. */
  6. function Html5notification() {
  7. var h5n = new Object();
  8. h5n.issupport = function() {
  9. var is = !!window.webkitNotifications;
  10. if(is) {
  11. if(window.webkitNotifications.checkPermission() > 0) {
  12. window.onclick = function() {
  13. window.webkitNotifications.requestPermission();
  14. }
  15. }
  16. }
  17. return is;
  18. };
  19. h5n.shownotification = function(replaceid, url, imgurl, subject, message) {
  20. if(window.webkitNotifications.checkPermission() > 0) {
  21. window.webkitNotifications.requestPermission();
  22. } else {
  23. var notify = window.webkitNotifications.createNotification(imgurl, subject, message);
  24. notify.replaceId = replaceid;
  25. notify.onclick = function() {
  26. window.focus();
  27. window.location.href = url;
  28. notify.cancel();
  29. };
  30. notify.show();
  31. }
  32. };
  33. return h5n;
  34. }