如何以编程方式在Chrome扩展程序中设置新标签页?

时间:2014-10-09 10:14:25

标签: google-chrome-extension

因此,默认情况下,新标签页将替换为我的Chrome扩展程序(通过清单)。但是,我想提供禁用它的选项(以编程方式)。

我该怎么做?

1 个答案:

答案 0 :(得分:3)

Google制作了星球大战新标签替换版,可让您查看默认的新标签页。它使用的网址是chrome-search://local-ntp/local-ntp.html。例如:

options.html:

<input type="checkbox"> Use default new tab page

options.js:

var checkbox = document.querySelector("input[type=checkbox]")
checkbox.addEventListener("click", function() {
 chrome.storage.sync.set({ defaultnewtab: checkbox.checked })
})

newtab.js:

chrome.storage.sync.get("defaultnewtab", function(storage) {
 if(storage.defaultnewtab) {
  chrome.tabs.update({ url: "chrome-search://local-ntp/local-ntp.html" })
} })
相关问题