Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (window.webkitNotifications) {
- console.log("Notifications are supported!");
- } else {
- console.log("Notifications are not supported for this Browser/OS version yet.");
- }
- /**
- * This is a private function that asks the browser for permission to show notifications
- */
- function private_notify_requestPermission(callback, options) {
- window.webkitNotifications.requestPermission(callback, options);
- }
- /**
- * This calls the notification method
- */
- function notify_send(options) {
- switch(options.type) {
- case "desktop":
- private_notify_send_chrome_desktop(options);
- break;
- case "html":
- private_notify_send_chrome_html_page(options);
- break;
- default:
- alert(options.message);
- break;
- }
- }
- /**
- * This is a private function that show a Text notification
- */
- function private_notify_send_chrome_desktop(options) {
- if (window.webkitNotifications.checkPermission() > 0) {
- private_notify_requestPermission(notify_send, options);
- }
- // Show the popup
- var popup = window.webkitNotifications.createNotification(options.icon, options.title, options.message);
- popup.show();
- }
- /**
- * This is a private function that show a HTML Page in a notification
- */
- function private_notify_send_chrome_html_page(options) {
- if (window.webkitNotifications.checkPermission() > 0) {
- private_notify_requestPermission(notify_send, options);
- }
- // Show the popup
- var popup = window.webkitNotifications.createHTMLNotification(options.file);
- popup.show();
- }
Add Comment
Please, Sign In to add comment