Chrome 扩展弹窗安装
Chrome extension popup installation
这是一个愚蠢的问题,但我找不到任何帮助。
我想知道如何让我的 chrome 扩展程序在用户安装时,将他重定向到带有我网站 link 的新选项卡中?
我应该把这段代码放在哪里?
在background.js我问。
到目前为止我的background.js是这个代码
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.
如您所料,它应该进入您的后台脚本。
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
chrome.tabs.create({url: "http://example.com/"});
这是一个愚蠢的问题,但我找不到任何帮助。
我想知道如何让我的 chrome 扩展程序在用户安装时,将他重定向到带有我网站 link 的新选项卡中?
我应该把这段代码放在哪里? 在background.js我问。
到目前为止我的background.js是这个代码
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.
如您所料,它应该进入您的后台脚本。
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
chrome.tabs.create({url: "http://example.com/"});