Google Chrome扩展程序可在用户点击后关闭通知 [英] Google Chrome extension to close notification after user click
本文介绍了Google Chrome扩展程序可在用户点击后关闭通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Chrome扩展程序正常运行。我的问题是通知在7秒后关闭。我希望用户点击关闭通知。
The Chrome extension works fine. My problem is that the notification closes in 7 seconds. I want for the user click to close the notification.
function engine(){
var latestId;
var ids;
var messages = [];
var newmessage = [];
$.get('http://localhost/site/json.php',function (data){
var json = $.parseJSON(data);
messages = json;
ids = json[0].id;
if(latestId == ids){
//no update
}else if(latestId === undefined){
var run = {
type: "basic",
title: "Title",
message: "Some message",
iconUrl : "icon.png",
};
chrome.notifications.create(run);
}
});
}
推荐答案
首先创建通知并提供它是一个notificationID参数,以便稍后关闭它。
First create your notification and give it a notificationID parameter to close it later.
var notification = {
type:"basic",
title:"News From Us!",
message:"Google Chrome Updated to v50!",
iconUrl:"assets/images/icon.png"
};
chrome.notifications.create("notfyId",notification);
点击通知后,您可以使用其ID(notfyId)关闭通知
On notification click you can close notification using its id (which is "notfyId")
function forwardNotfy(){
chrome.notifications.clear("notfyId");
window.open(url); //optional
}
chrome.notifications.onClicked.addListener(forwardNotfy);
现在,当您点击通知时,它将关闭。
Now, when you click your notification it'll close.
这篇关于Google Chrome扩展程序可在用户点击后关闭通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文