res*_*efm 34 desktop notifications web-applications
我想做的是优先显示烤面包机通知,但任何"推送"桌面更新的方法都很有趣.
谢谢
Dan*_*scu 133
以下是从Chrome桌面通知示例复制的Chrome,Firefox,Opera和Safari 桌面通知的工作示例.在JSBin上
试一试吧.
// request permission on page load
document.addEventListener('DOMContentLoaded', function () {
if (Notification.permission !== "granted")
Notification.requestPermission();
});
function notifyMe() {
if (!Notification) {
alert('Desktop notifications not available in your browser. Try Chromium.');
return;
}
if (Notification.permission !== "granted")
Notification.requestPermission();
else {
var notification = new Notification('Notification title', {
icon: 'http://cdn.sstatic.net/stackexchange/img/logos/so/so-icon.png',
body: "Hey there! You've been notified!",
});
notification.onclick = function () {
window.open("https://stackoverflow.com/a/13328397/1269037");
};
}
}
Run Code Online (Sandbox Code Playgroud)
<button onclick="notifyMe()">Notify me!</button>
Run Code Online (Sandbox Code Playgroud)
有关这方面的详细信息,请参阅我对Chrome桌面通知示例的回答.
| 归档时间: |
|
| 查看次数: |
49004 次 |
| 最近记录: |