<a onclick="showNotification();">show Notification</a>
<script>
function showNotification () {
window.Notification.permission = "granted";
alert(window.Notification.permission);
if (window.Notification){
if (window.Notification.permission == "granted") {
var notification = new Notification(‘标题‘, {
body: "内容",
icon: "图标路径,若不指定默认为favicon"
});
setTimeout(function(){notification.close();},5000);
} else {
window.Notification.requestPermission();
}
}else alert(‘你的浏览器不支持此消息提示功能,请使用chrome内核的浏览器!‘);
};
</script>
时间: 2024-11-05 01:05:00