Created
July 29, 2012 14:46
-
-
Save paulgibbs/3199341 to your computer and use it in GitHub Desktop.
Web Notifications POC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// very rough, basic javascript calls to use the W3 Web Notifications api, rather than all the webkitNotifications stuff which you find in google. | |
(function($) { | |
$(document).ready(function() { | |
// Ask for permission | |
$('#ask_permission').click(function(e) { | |
e.preventDefault(); | |
// webkitNotifications.requestPermission(function(){}); // use this for safari / w3 standards | |
// window.Notification.requestPermission(function(e) { alert(e); }); // use this for chrome (w3 standard causes a crash) | |
}); | |
// Display the plain text notification | |
// 'tag' replaces the existing notification, to prevent duplicate achievements | |
$('#plain_form').submit(function(e) { | |
new Notification("New Email mo", { tag: 'again', body: "moo world" } ); | |
}); | |
}); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
tried that in chrome, still same error so in my plugin you have 2 options,
$.notifications.requestPermission() - basically you have to add this to an element's click event for it to work in chrome
$.notifications.notificationPrompt() - this shows a overlay explaining the site needs to use notifications, and then when user clicks to close overlay this is is able to fire $ .notifications.requestPermission();