Skip to content

Instantly share code, notes, and snippets.

@damienklinnert
Created July 13, 2012 08:52
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save damienklinnert/3103743 to your computer and use it in GitHub Desktop.
Save damienklinnert/3103743 to your computer and use it in GitHub Desktop.
a simple test for html notifications from html5rocks at http://www.html5rocks.com/en/tutorials/notifications/quick/
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>notifications</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>
$(function () {
if (window.webkitNotifications) {
console.log('Notifications are supported!');
console.log(webkitNotifications);
} else {
console.log('Notifications are not supported!');
}
var createNotificationInstance = function (options) {
if (options.notificationType === 'simple') {
return window.webkitNotifications.createNotification(
'icon.png',
'Notification title',
'Notification content ...'
);
} else if (options.notificationType === 'html') {
return window.webkitNotifications.createHTMLNotification('http://damienklinnert.de');
}
};
$('button').click(function (e) {
if (window.webkitNotifications.checkPermission() == 0) {
createNotificationInstance({notificationType:'simple'}).show();
} else {
window.webkitNotifications.requestPermission(function () {});
}
});
});
</script>
</head>
<body>
<button>alert</button>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment