让 Chrome 应用程序 window 在屏幕右下角打开
Getting a Chrome app window to open at the bottom right of screen
我希望我的 Chrome 应用程序打开时接触到任务栏并且正好偏离屏幕右侧。
我当前的代码:
chrome.app.runtime.onLaunched.addListener(function() {
chrome.app.window.create('window.html', {
'bounds': {
'width': 300,
'height': 325
},
'resizable': false,
frame: 'none'
});
});
如果您可以设置 outer 边界,即完整的 window 大小(并且内容可能更小),那么很简单:
chrome.app.runtime.onLaunched.addListener(function() {
var windowWidth = 300;
var windowHeight = 325;
chrome.app.window.create('window.html', {
outerBounds: { // 'bounds' is deprecated, and you want full window size
width: windowWidth,
height: windowHeight,
left: screen.availWidth - windowWidth,
top: screen.availHeight - windowHeight,
},
resizable: false,
frame: 'none'
});
});
如果你想设置inner bounds,也就是window内容的确切大小,那么你无法预测[=24]的大小=]准确。您必须先创建它,然后在回调中重新定位它:
chrome.app.runtime.onLaunched.addListener(function() {
var windowWidth = 300;
var windowHeight = 325;
chrome.app.window.create(
'window.html',
{
innerBounds: {
width: windowWidth,
height: windowHeight
},
resizable: false,
frame: 'none'
},
function(win) {
win.outerBounds.setPosition(
screen.availWidth - win.outerBounds.width, // left
screen.availHeight - win.outerBounds.height // top
);
}
);
});
总而言之,查看 chrome.app.window
API 的实际文档是个好主意。
我希望我的 Chrome 应用程序打开时接触到任务栏并且正好偏离屏幕右侧。
我当前的代码:
chrome.app.runtime.onLaunched.addListener(function() {
chrome.app.window.create('window.html', {
'bounds': {
'width': 300,
'height': 325
},
'resizable': false,
frame: 'none'
});
});
如果您可以设置 outer 边界,即完整的 window 大小(并且内容可能更小),那么很简单:
chrome.app.runtime.onLaunched.addListener(function() {
var windowWidth = 300;
var windowHeight = 325;
chrome.app.window.create('window.html', {
outerBounds: { // 'bounds' is deprecated, and you want full window size
width: windowWidth,
height: windowHeight,
left: screen.availWidth - windowWidth,
top: screen.availHeight - windowHeight,
},
resizable: false,
frame: 'none'
});
});
如果你想设置inner bounds,也就是window内容的确切大小,那么你无法预测[=24]的大小=]准确。您必须先创建它,然后在回调中重新定位它:
chrome.app.runtime.onLaunched.addListener(function() {
var windowWidth = 300;
var windowHeight = 325;
chrome.app.window.create(
'window.html',
{
innerBounds: {
width: windowWidth,
height: windowHeight
},
resizable: false,
frame: 'none'
},
function(win) {
win.outerBounds.setPosition(
screen.availWidth - win.outerBounds.width, // left
screen.availHeight - win.outerBounds.height // top
);
}
);
});
总而言之,查看 chrome.app.window
API 的实际文档是个好主意。