如何在 chrome 扩展中实现带有声音的通知弹出窗口。
就像 Checker Plus for Gmail
最佳答案
我认为 createHTMLNotification
自从接受的答案被写入以来,已被弃用。对于现在发生在此线程上的任何人,假设您拥有 notifications
,这是一种自 2014 年 1 月起有效的方法。 list 中的权限:
背景.js
createNotification();
audioNotification();
function audioNotification(){
var yourSound = new Audio('yourSound.mp3');
yourSound.play();
}
function createNotification(){
var opt = {type: "basic",title: "Your Title",message: "Your message",iconUrl: "your_icon.png"}
chrome.notifications.create("notificationName",opt,function(){});
//include this line if you want to clear the notification after 5 seconds
setTimeout(function(){chrome.notifications.clear("notificationName",function(){});},5000);
}
这里的一般想法是您将发送常规通知,然后在通知创建后立即使用普通的 JavaScript 方法播放声音。当然还有其他方法可以做到这一点并组织它,但我认为这在大多数情况下非常清楚并且很容易实现。
关于google-chrome-extension - 如何在 chrome 扩展中实现带有声音的通知弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14917531/