Reputation:
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?
And where should i put this code? On the background.js i quess.
until now my background.js is this code
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??
Upvotes: 0
Views: 1162
Reputation: 77482
For "when it is being installed", there is a special event in 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.
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.create({url: "http://example.com/"});
Upvotes: 4