Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在chrome扩展中调用notify函数时,是否打开定义的其他页面?_Javascript_Jquery_Google Chrome Extension - Fatal编程技术网

Javascript 在chrome扩展中调用notify函数时,是否打开定义的其他页面?

Javascript 在chrome扩展中调用notify函数时,是否打开定义的其他页面?,javascript,jquery,google-chrome-extension,Javascript,Jquery,Google Chrome Extension,在我的代码中,我希望每次都能够使用不同的链接调用函数notify,并且创建的特定通知在单击时会打开一个包含该页面的新选项卡 注意:我对这些文档感到非常困惑,请不要只是将我与之联系起来,我真的想用一个例子来解释。谢谢 这就是我到目前为止所做的: function notify(title, msg, link, callback) { //no idea what to do with the link here var options = { title: tit

在我的代码中,我希望每次都能够使用不同的链接调用函数notify,并且创建的特定通知在单击时会打开一个包含该页面的新选项卡 注意:我对这些文档感到非常困惑,请不要只是将我与之联系起来,我真的想用一个例子来解释。谢谢

这就是我到目前为止所做的:

function notify(title, msg, link, callback) {
    //no idea what to do with the link here
    var options = {
        title: title,
        message: msg,
        type: "basic", 
        iconUrl: "Icon.png" 
    };
    return chrome.notifications.create("", options, callback);
}
并调用该函数:

通知(“标题”、“消息”http://www.example.com“,职能(通知){})

哪个会显示

头衔 信息

单击后,将打开一个新选项卡

后来,我会再打一次电话
通知(“标题”、“消息”http://www.google.com“,职能(通知){})

当点击时,它会打开一个新的标签


如果你能帮忙,谢谢你

不直接支持将
onclick
处理程序附加到通知。相反,如果单击通知的正文,它将生成一个常规事件,提供通知的ID

因此,您必须维护自己的ID与URL的匹配

var urls = {};

chrome.notifications.onClicked.addListener(notifyClick);
chrome.notifications.onClosed.addListener(notifyClose);

function notify(title, msg, link, callback) {
  var options = {
    title: title,
    message: msg,
    type: "basic", 
    iconUrl: "Icon.png",
    isClickable: true // New in Chrome 32, alters the appearance?
  };
  return chrome.notifications.create("", options, function(id) {
    // New ID will be generated
    urls[id] = link;
  });
}

function notifyClick(id) {
  // Look up the URL:
  chrome.tabs.create({url: urls[id]});
  // Optionally, close the notification:
  // chrome.notifications.clear(id, function(){});
}

function notifyClose(id, byUser) {
  // Clean up the matching
  delete urls[id];
}

请注意:关于以编程方式关闭通知,有一个警告。如果信息中心关闭了通知,.

我真的被它弄糊涂了,虽然是的,我有,你能帮我吗?谢谢,我正在写一个答案。谢谢,我很感激