-
-
Save paulgibbs/3199341 to your computer and use it in GitHub Desktop.
// 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); |
ah ok, im using $.notification instead mainly because Safari's is half there with window.Notification but is mostly using the webkitNotifications. Do a clone of what I have done so far and try it out in different browsers, working quite well at moment, one limitation I have found in chrome is that you seem to have to have the user click something before you can request permission (tweeting Paul Irish confirmed this)
What more of the spec is there beyond requesting permission , and adding a notification?
Thanks for the heads-up about Chrome; that's annoying. I'll have to test triggering a click event on some hidden object, on page load.
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
I'm looking for a lightweight Web Notifications implementation that uses the window.Notification format (per the spec), rather than the webkitNotifications support. While searching to see if there was a polyfil for Firefox/IE9 I found your new github project, so am interested to see what it grows into.
The above gist is basically just a note to myself as I'd spent a while trying to get it working on a test page.