Set Interval in Google Chrome Extension

痴心易碎 提交于 2020-01-25 04:26:27

问题


I'm writing a google chrome extension that gives the user a new word everyday. This word appears in the popup and is inserted into an array so they can study them later. In my background.js I have the classic setInterval, like below:

setInterval(function(){ 
...code to get new word and push to array
}, (12*3600000));

The problem however is that this functions works on every tab open! So I left it for a day with 10 tabs open and I had 10 new words. How can I have a function within a google chrome extension that only runs once a day, independent of how many tabs are open? Should this function live in another page? The only other js pages I have are popup.js and options.js and I believe those only run when popup.html and options.html are open. Thanks!

来源:https://stackoverflow.com/questions/31094918/set-interval-in-google-chrome-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!