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); |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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)