Guest User

Untitled

a guest
Jul 20th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. if (window.webkitNotifications) {
  2. console.log("Notifications are supported!");
  3. } else {
  4. console.log("Notifications are not supported for this Browser/OS version yet.");
  5. }
  6.  
  7. /**
  8. * This is a private function that asks the browser for permission to show notifications
  9. */
  10. function private_notify_requestPermission(callback, options) {
  11. window.webkitNotifications.requestPermission(callback, options);
  12. }
  13.  
  14. /**
  15. * This calls the notification method
  16. */
  17. function notify_send(options) {
  18. switch(options.type) {
  19. case "desktop":
  20. private_notify_send_chrome_desktop(options);
  21. break;
  22.  
  23. case "html":
  24. private_notify_send_chrome_html_page(options);
  25. break;
  26.  
  27. default:
  28. alert(options.message);
  29. break;
  30. }
  31. }
  32.  
  33. /**
  34. * This is a private function that show a Text notification
  35. */
  36. function private_notify_send_chrome_desktop(options) {
  37. if (window.webkitNotifications.checkPermission() > 0) {
  38. private_notify_requestPermission(notify_send, options);
  39. }
  40.  
  41. // Show the popup
  42. var popup = window.webkitNotifications.createNotification(options.icon, options.title, options.message);
  43. popup.show();
  44. }
  45.  
  46. /**
  47. * This is a private function that show a HTML Page in a notification
  48. */
  49. function private_notify_send_chrome_html_page(options) {
  50. if (window.webkitNotifications.checkPermission() > 0) {
  51. private_notify_requestPermission(notify_send, options);
  52. }
  53.  
  54. // Show the popup
  55. var popup = window.webkitNotifications.createHTMLNotification(options.file);
  56. popup.show();
  57. }
Add Comment
Please, Sign In to add comment