Created
May 31, 2015 05:22
-
-
Save mikeobrien/f84998a30b43cc8b8b86 to your computer and use it in GitHub Desktop.
Notifications
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
<button id="favicon-change" class="btn btn-default">Change Header</button> | |
<button id="notification" class="btn btn-default">Notification</button> |
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
<script type="text/javascript"> | |
$(function() { | |
$('#favicon-change').click(function() { | |
if ($('#favicon').attr('href') == 'img/favicon-alert.png') | |
$('#favicon').attr('href', 'img/favicon.png'); | |
else $('#favicon').attr('href', 'img/favicon-alert.png'); | |
}); | |
$('#notification').click(function() { | |
var sendMessage = function() { | |
var notification = new Notification("Hi there!", { | |
body: 'Do you like my body?', | |
icon: 'img/notification-icon.png' | |
}); | |
new Audio('media/knock_brush.mp3').play(); | |
setTimeout(notification.close.bind(notification), 10000); | |
}; | |
if (!("Notification" in window)) { | |
console.log('notifications not supported!'); | |
} | |
else if (Notification.permission === "granted") { | |
console.log('notification sent'); | |
sendMessage(); | |
} | |
else if (Notification.permission !== 'denied') { | |
console.log('Asking permission'); | |
Notification.requestPermission(function (permission) { | |
if (permission === "granted") { | |
console.log('permission granted'); | |
sendMessage(); | |
} | |
}); | |
} | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment