hitode909の日記

以前はプログラミング日記でしたが、今は子育て日記です

デスクトップ通知

普通に出していくと,デスクトップ通知で画面がいっぱいになってしまうことがある.
そう重要でない情報であれば,通知を出すときに,もう出ていれば,前のをすぐに消してから新しいのを出すと,邪魔にならない.
こういう感じ.

if (notification) {
    notification.cancel();
}
if (timer) {
    clearTimeout(timer);
}
notification = webkitNotifications.createNotification();
notification.show();
 timer = setTimeout(function() {
    notification.cancel();
    notification = null;
    timer = null;
}, 2000);

一方,重要でない情報を通知するのはやめたほうがいい気もする.