Javascript 如何为新窗口创建自定义google chrome扩展,并在扩展的备选点击中保持新窗口的焦点
我想创建一个新的自定义chrome扩展名,以便在新窗口中打开web URL或自定义页面。要添加新的chrome扩展名,必须有2个文件Javascript 如何为新窗口创建自定义google chrome扩展,并在扩展的备选点击中保持新窗口的焦点,javascript,google-chrome-extension,manifest.json,Javascript,Google Chrome Extension,Manifest.json,我想创建一个新的自定义chrome扩展名,以便在新窗口中打开web URL或自定义页面。要添加新的chrome扩展名,必须有2个文件 manifest.json background.js 下面是创建新的自定义chrome扩展以在新chrome窗口中打开web URL或自定义页面的示例 创建一个新文件夹,并将上述两个文件添加到该文件夹中 您的manifest.json文件如下所示: { “清单版本”:2, “名称”:“新窗口”, “版本”:“0.1”, “权限”:[ "https://gith
/**
* Listens for the app launching then creates the window
*/
var ba = chrome.browserAction;
// Function to open the chrome extension into new chrome window
var windowNotOpenTitle = 'Open popup window';
var windowIsOpenTitle = 'Popup window is already open. Click to focus popup.';
var popupWindowId = false; //popupWindowId can be true, false, or the popup's window Id.
ba.onClicked.addListener(function () {
let width= 1100;
let height= 650;
if(popupWindowId === false){
popupWindowId = true; //Prevent user pressing the button multiple times.
ba.setTitle({title:windowIsOpenTitle});
chrome.windows.create({
'url': 'https://github.com/',
'type': 'panel',
'width': width,
'height': height,
'left': (screen.width/2) - (width/2),
'top': (screen.height/2) - (height/2),
'focused': true
},function(win){
popupWindowId = win.id;
});
return;
}else if(typeof popupWindowId === 'number'){
//The window is open, and the user clicked the button., Focus the window.
chrome.windows.update(popupWindowId,{focused:true});
}
});
在新窗口大小中,可以定义宽度和高度。
另一部分是在最小化新窗口后将焦点放在相同的窗口id上。
查找以下步骤以在本地启动chrome扩展(开发模式)
步骤:
对于代码池:您可以根据需要在函数chrome.windows.create()中修改URL