关于javascript:Chrome扩展程序弹出窗口安装

Chrome extension popup installation

这是一个愚蠢的问题,但我在搜索时找不到任何帮助。

我想知道我如何在用户安装chrome扩展程序后使其重新定向到带有我网站链接的新标签中?

该代码应该放在哪里?
我在background.js上查询。

直到现在我的background.js是这段代码

1
2
3
4
5
6
7
8
9
10
11
12
chrome.browserAction.onClicked.addListener(function(tab) {
    chrome.tabs.executeScript(tab.id, {
    allFrames: true,
        file:"content_script.js"
    }, function() {
        if (chrome.runtime.lastError) {
            console.error(chrome.runtime.lastError.message);
        }
    });


});

关于我应该添加什么的任何想法?


对于"何时安装",chrome.runtime API中有一个特殊事件:

onInstalled

Fired when the extension is first installed, when the extension is updated to a new version, and when Chrome is updated to a new version.

您猜对了,应该转到您的后台脚本。

1
2
3
4
5
6
7
8
9
10
chrome.runtime.onInstalled.addListener( function(details) {
  switch(details.reason) {
    case"install":
      // First installation
      break;
    case"update":
      // First run after an update
      break;
  }
});

要使用您的URL打开新标签,您可以使用chrome.tabs

1
chrome.tabs.create({url:"http://example.com/"});