使用所描述的星球大戰方法@Daniel Herr,我做了這個,效果很好。雖然感覺有點黑客。
我有一個選項在popup.html
中設置,無論分機是否「打開」。
首先,設置使用Chrome定義的方法的默認新標籤頁:
manifest.json的
"chrome_url_overrides": {
"newtab": "newtab.html"
},
然後在你的分機的呼叫newtab.html
一個新的JavaScript文件,newtab.js
(或任何)。
我也使用jQuery,所以我的代碼使用它,但您可以使用DOMContentLoaded本地執行此操作。
newtab。JS
$(document).ready(function(){
// It takes a moment for the Chrome query/update so sometimes there is a flash of content
// Hiding the Body makes it look blank/white until either redirected or shown
\t $('body').hide();
\t var background = chrome.extension.getBackgroundPage();
\t var _app = background._app;
\t // App is OFF, show Default New Tab
\t if(!_app._on){
\t \t // Get the current Tab
\t \t chrome.tabs.query({ active: true, currentWindow: true }, function(tabs) {
\t \t \t var active = tabs[0].id;
// Set the URL to the Local-NTP (New Tab Page)
\t \t \t chrome.tabs.update(active, { url: "chrome-search://local-ntp/local-ntp.html" }, function() { });
\t \t });
\t // App is ON, show custom content
\t } else {
\t \t
\t \t $('body').show();
\t }
});
基本上,方法是使其被重定向到chrome-search://local-ntp/local-ntp.html
這是很難URL爲默認瀏覽器NTP更新選項卡。
由於這是Chrome內部網址 - 網址字段仍顯示爲空白。
這很可能違背了谷歌針對擴展的單一目的政策。您要麼是新標籤的替代品,要麼不是。 – Xan