Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/410.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通知_Javascript_Google Chrome Extension_Notifications - Fatal编程技术网

Javascript 自动显示扩展中的chrome通知

Javascript 自动显示扩展中的chrome通知,javascript,google-chrome-extension,notifications,Javascript,Google Chrome Extension,Notifications,我正在做一个chrome扩展,它会在一段时间后自动提醒我喝水。到目前为止,我编写的代码在一段时间后显示通知,但只有在我单击扩展之后。我希望通知自动弹出,而不必点击通知 这是我试过的密码 function show() { var interval = { type: "basic", iconUrl: "icon48.png", title: "Drink water", message: "Its time to hyd

我正在做一个chrome扩展,它会在一段时间后自动提醒我喝水。到目前为止,我编写的代码在一段时间后显示通知,但只有在我单击扩展之后。我希望通知自动弹出,而不必点击通知

这是我试过的密码

 function show() {
    var interval = {
        type: "basic",
        iconUrl: "icon48.png",
        title: "Drink water",
        message: "Its time to hydrate yourself!"
    }
    chrome.notifications.create('drink', interval);
}
  setInterval(show, 2000);

听起来你在使用一个弹出窗口,只有你点击它,它才会被激活。改为使用,以便在您更改页面或退出弹出窗口后保持状态。@RossJacobs谢谢您的帮助,但是您能告诉我如何访问该后台脚本中的dom元素吗?就像我希望时间由用户给定一样,那么我将如何从html页面访问它?内容脚本将向后台脚本发送消息。我给你的链接引用了这个内部消息。