[英]Chrome extension popup installation
This is kind of a stupid question but i couldnt find any help searching around. 这是一个愚蠢的问题,但我找不到任何帮助。
I would like to know how can i make my chrome extension, when its being installed by a user, to redirect him in a new tab with a link of my website? 我想知道我如何在用户安装chrome扩展程序后使其重新定向到带有我的网站链接的新标签中?
And where should i put this code? 我应该把这段代码放在哪里? On the background.js i quess.
我在background.js上查询。
until now my background.js is this code 直到现在我的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);
}
});
});
Any idea of what should i add?? 我应该添加什么的任何想法?
For "when it is being installed", there is a special event in chrome.runtime
API: 对于“正在安装时”,
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更新为新版本时触发。
As you guessed correctly, it should go to your background script. 您猜对了,应该转到您的后台脚本。
chrome.runtime.onInstalled.addListener( function(details) {
switch(details.reason) {
case "install":
// First installation
break;
case "update":
// First run after an update
break;
}
});
To open a new tab with your URL, you can use chrome.tabs
要使用您的网址打开一个新标签,您可以使用
chrome.tabs
chrome.tabs.create({url: "http://example.com/"});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.