让Chrome应用窗口在屏幕右下角打开 [英] Getting a Chrome app window to open at the bottom right of screen

查看:438
本文介绍了让Chrome应用窗口在屏幕右下角打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的Chrome应用程序打开,以便触摸任务栏,只是偏离屏幕右侧。

I would like my Chrome app to open so it's touching the task bar and just offset from the right of the screen.

我当前的代码:

chrome.app.runtime.onLaunched.addListener(function() {
  chrome.app.window.create('window.html', {
    'bounds': {
      'width': 300,
      'height': 325
    },
    'resizable': false,
    frame: 'none'
  });      
});


推荐答案

如果你没有设置外部边界,即完整的窗口大小(内容可能更小),然后很简单:

If you're okay with setting the outer bounds, that is, the full window size (and the content is potentially smaller), then it's simple:

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'
  });      
});

如果你想设置内部边界,那就是确切的大小窗口内容,则无法准确预测窗口的大小。你必须先创建它,然后在回调中重新定位它:

If you want to set inner bounds, that is the exact size of the window content, then you can't predict the size of the window accurately. You'll have to first create it and then reposition it in the callback:

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

All in all, it'a a good idea to review the actual documentation of chrome.app.window API.

这篇关于让Chrome应用窗口在屏幕右下角打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆