如何在第三方站点上推送 html5 通知时执行代码
How to execute code when html5 notification is pushed on 3rd party site
我有一个使用通知的网站(gitter.im),我想在推送通知时运行声音。如何将此代码添加到通知中?
(function() {
var a = document.createElement('audio')
a.setAttribute('autoplay', true)
a.setAttribute('src', 'http://www.soundjay.com/button/beep-03.mp3')
})();
您可以使用 HTML5 音频 api,但它在 service worker 中不起作用。
当浏览器收到通知时发出声音的唯一方法是通过postMessage(),您可以通知网页发出声音,但只有在浏览器中打开主站点页面时,它才会起作用。
(Chrome ServiceWorker postMessage)
var track = new Audio("http://oringz.com/oringz-uploads/sounds-874-gets-in-the-way.mp3");
track.play();
更多信息:http://www.html5rocks.com/en/tutorials/webaudio/intro/
这
似乎有效:
(function(Notif) {
function play() {
var a = document.createElement('audio')
a.setAttribute('autoplay', true)
a.setAttribute('src', 'http://www.soundjay.com/button/beep-03.mp3');
}
window.Notification = function(title, option) {
var notif = new Notif(title, option);
play();
return notif;
};
for (var key in Notif) {
if (Notif.hasOwnProperty(key)) {
window.Notification[key] = Notif[key];
}
}
})(Notification);
相关文章:
- Canvas Html5绘图应用程序,移动画布会导致重大问题
- 如何使用phaser使html5游戏在移动设备浏览器上运行
- HTML5音频加载和播放获胜'我不能在iPad上工作
- HTML5页面底部棒
- 如何将RSS提要推送到HTML5通知
- 删除HTML5通知权限
- 当新的Wordpress帖子发布时触发HTML5通知
- 如何在第三方站点上推送 html5 通知时执行代码
- 如何在 html5 桌面通知中添加简单链接
- 让 HTML5 通知在延迟后消失
- HTML5 web应用程序中的推送通知/消息
- HTML5通知图像中的圆角
- HTML5通知与服务工作者在Chrome移动不工作
- 当窗口最小化时,提醒用户浏览器内事件——而不是html5通知
- HTML5通知和许可的问题
- 为一个HTML5 Django web应用实现一个实时通知系统
- 延迟HTML5通知
- HTML5通知不工作在移动Chrome
- HTML5通知中的表单元素
- 如何根据在 HTML5 中使用服务器发送的事件检索的数据显示通知