1

所以,我有我的 chrome 扩展程序,可以在后台正常运行。每隔几个小时,它就会使用通知 API 向用户提问。

如果他们单击一个答案,我们将在当前窗口中打开一个选项卡。

问题:如果没有打开 chrome 窗口(即扩展程序作为“让 google chrome 在后台运行”选项的一部分运行),则选项卡不会打开。

只要至少打开一个 chrome 窗口,下面的代码就可以正常工作:

// tried this too: chrome.windows.create();
chrome.tabs.create({url: pathToGo});

如果没有打开的窗口,如何使“chrome.windows.create()”实际创建一个窗口。

4

1 回答 1

0

使用chrome.windows.getAll(object getInfo, function callback)API 获取所有打开的窗口。如果在回调中,窗口数组为空,则使用chrome.windows.create(object createData, function callback).

chrome.notifications如果您无法创建新窗口, 请使用API。http://developer.chrome.com/extensions/notifications.html

于 2013-09-24T09:12:53.583 回答