【问题标题】:How do I programmatically set the new tab page in a Chrome Extension?如何以编程方式在 Chrome 扩展程序中设置新标签页?
【发布时间】:2014-10-09 10:14:24
【问题描述】:

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

我该怎么做?

【问题讨论】:

    标签: google-chrome-extension


    【解决方案1】:

    Google 做了一个星球大战新标签替换,允许您查看默认的新标签页。它使用的 url 是 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" })
    } })
    

    【讨论】:

    • 这并不总是有效。扩展程序应该显示最后设置的新标签页,而不是 Chrome 的默认页。
    猜你喜欢
    • 1970-01-01
    • 2012-04-30
    • 1970-01-01
    • 2014-05-10
    • 2013-05-06
    • 1970-01-01
    • 1970-01-01
    • 2017-05-10
    • 1970-01-01
    相关资源
    最近更新 更多