Last active
December 26, 2015 06:51
-
-
Save kidatti/33e71e1b8a5f9ed8d92f to your computer and use it in GitHub Desktop.
JavaScriptでデスクトップ通知(HTML5 Notification) ref: http://qiita.com/kidatti/items/10a6a033ed0b84619d81
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Desktop Notification</title> | |
</head> | |
<body> | |
<script> | |
// Notification対応しているかどうか | |
if (window.Notification) { | |
alert('Notificationは有効です'); | |
// Permissionの確認 | |
if (Notification.permission === 'granted') { | |
// 許可されている場合はNotificationで通知 | |
alert('通知許可されています'); | |
var n = new Notification("Hello World"); | |
} else if (Notification.permission === 'denied') { | |
alert('通知拒否されています'); | |
} else if (Notification.permission === 'default') { | |
alert('通知可能か不明です'); | |
// 許可が取れていない場合はNotificationの許可を取る | |
Notification.requestPermission(function(result) { | |
if (result === 'denied') { | |
alert('リクエスト結果:通知許可されませんでした'); | |
} else if (result === 'default') { | |
alert('リクエスト結果:通知可能か不明です'); | |
} else if (result === 'granted') { | |
alert('リクエスト結果:通知許可されました!!'); | |
var n = new Notification("Hello World"); | |
} | |
}) | |
} | |
} else { | |
alert('Notificationは無効です'); | |
} | |
</script> | |
</body> | |
</html> |
This file contains 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
var n = new Notification("Hello World"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment