webkitnotifications在Chrome中不起作用

亚历克斯

我有一个扩展程序,可以显示通知,并且在chrome更新之前可以正常工作,并且在Chrome浏览器上无法再使用了。

我应该在此代码上进行哪些编辑才能使其正常工作。这是我的代码。

deskNoti=webkitNotifications.createNotification(chrome.app.getDetails().name,'You have '+counter+' new messages');
deskNoti.onclick=function(){openPage();this.cancel()
};
deskNoti.show();
	
if(timeNoti){window.setTimeout(function(){deskNoti.cancel();},timeNoti);}

可汗

webkitNotifications已被删除。直接替换为Notifications API

该代码易于翻译:

// Instead of calling a create function, one calls the "new" operator:
deskNoti = new Notification(
  chrome.app.getDetails().name,
  // Instead of just message text, the second parameter is now an object
  //  with multiple properties. Message text should go into "body" parameter:
  { body: 'You have '+counter+' new messages' }
);

// Instead of .cancel(), the function to close the notification is now .close()
deskNoti.onclick = function() { openPage(); this.close() };

// Notifications are now shown automatically; there is no .show() function
//deskNoti.show();

if(timeNoti) {
  window.setTimeout(function() { deskNoti.close(); }, timeNoti);
}

考虑改用chrome.notificationsAPI

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章