chrome扩展:如何使对话框位于当前窗口的右侧?
本文介绍了chrome扩展: 如何使扩展对话框位于当前窗口的右侧的处理方法。
chrome.action.onClicked.addListener(async function(tab){
var windows = await chrome.windows.getAll({populate: true, windowTypes: ["popup"]}) || []
// 在这边我的处理是只能显示一个对话框,每次判断有没有已存在的对话框,如果有则取上一次的对话框给予焦点
if(windows.length > 0){
var lastFoucsedWindow = await chrome.windows.getLastFocused({
populate: true, windowTypes: ["popup"]
})
if(!lastFoucsedWindow.focused){
chrome.windows.update(lastFoucsedWindow.id, {focused: true});
}
}else{
chrome.windows.getCurrent(function(w) {
// w 参数包含了浏览器窗口的信息,如 高度、宽度 ...
chrome.windows.create({tabId: tab.id,url: "popup.html", type: "popup", width:340,height:610,top: 80,left: (w.width - 450)});
});
}
})