我正试图让谷歌浏览器在检测到我的扩展程序安装时打开一个包含扩展程序信息的标签。
这是我到目前为止所拥有的,但它似乎没有起作用
chrome.runtime.onInstalled.addListener(function(details){
if(details.reason == "install"){
alert('This is the first run!');
chrome.extension.onRequest.addListener(function(request, sender) {
chrome.tabs.update(sender.tab.id, {url: request.redirect});
});
}else if(details.reason == "update"){
var thisVersion = chrome.runtime.getManifest().version;
alert('This is the update!');
}
});
先谢谢!
/// SOLUTION ///
我没有足够高的代表发布我自己的答案所以这里是...
我设法解决了这个问题。
chrome.runtime.onInstalled.addListener(function(details){
if(details.reason == "install"){
alert('This is the first run!');
window.open("firstrun.html");
}else if(details.reason == "update"){
var thisVersion = chrome.runtime.getManifest().version;
alert('This is the update!');
}
});
第一次安装扩展程序时,使用window.open("firstrun.html");
会在Google Chrome中打开一个新标签页。
希望这有助于其他人!
答案 0 :(得分:1)
我使用它并且效果很好
chrome.runtime.onInstalled.addListener(function(details){
if(details.reason == "install"){
chrome.tabs.create({ url: chrome.extension.getURL('welcome.html')});
}
});