Skip to content

Instantly share code, notes, and snippets.

@paulgibbs
Created July 29, 2012 14:46
Show Gist options
  • Save paulgibbs/3199341 to your computer and use it in GitHub Desktop.
Save paulgibbs/3199341 to your computer and use it in GitHub Desktop.
Web Notifications POC
// 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);
@jonathan-fielding
Copy link

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();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment