Javascript Chrome扩展桌面通知隐藏问题
我使用以下代码通过Chrome插件显示桌面通知:Javascript Chrome扩展桌面通知隐藏问题,javascript,google-chrome,google-chrome-extension,chromium,Javascript,Google Chrome,Google Chrome Extension,Chromium,我使用以下代码通过Chrome插件显示桌面通知: var notification = webkitNotifications.createNotification( 'img/48.png', 'my title', 'some text here' ); notification.show(); setTimeout(function(){ notification.cancel(); }, 3000); 通知显示得很好,但是我想在一段时间后通过setTimeout自动隐藏它,
var notification = webkitNotifications.createNotification(
'img/48.png',
'my title',
'some text here'
);
notification.show();
setTimeout(function(){
notification.cancel();
}, 3000);
通知显示得很好,但是我想在一段时间后通过setTimeout
自动隐藏它,但它没有隐藏,请保持在那里。根据API,它只有两种方法show
和cancel
我做错了什么?您的代码实际上对我很好。(在弹出式浏览器动作中测试,弹出式窗口在3秒钟后正确关闭)
您是否尝试设置断点以查看超时是否实际触发?它可以工作,但弹出窗口不会在3秒后自动隐藏,它永远不会。正如我所说,使用
setTimeout
在3秒后隐藏弹出窗口对我来说很有效。因此,您能否检查超时是否实际触发并调用notification.cancel()?