<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<title>Document</title>
<body>
<button>Notify me!</button>
<script>
// At first, let's check if we have permission for notification
// If not, let's ask for it
}
});
}
var button = document.getElementsByTagName('button')[0];
// If the user agreed to get notified
// Let's try to send ten notifications
for (var i = 0; i < 10; i++) {
// Thanks to the tag, we should only see the "Hi! 9" notification
var n = new Notification("Hi! " + i, {
});
}
}
// If the user hasn't told if he wants to be notified or not
// Note: because of Chrome, we are not sure the permission property
// is set, therefore it's unsafe to check for the "default" value.
}
// If the user said okay
if (status === "granted") {
for (var i = 0; i < 10; i++) {
// Thanks to the tag, we should only see the "Hi! 9" notification
var n = new Notification("Hi! " + i, {
});
}
}
// Otherwise, we can fallback to a regular modal alert
else {
}
});
}
// If the user refuses to get notified
else {
// We can fallback to a regular modal alert
}
});
});
</script>
</body>
</html>

• 多说评论
• 签名
• 新浪微博
• 默认评论