background - 如何设置 Chrome 应用程序相对于屏幕的大小

标签 background size google-chrome-app

为什么我的代码不起作用?我正在尝试将应用程序的大小设置为屏幕的 80%,因为我希望它适合任何显示器,如果有更好的方法我想知道。

background.js:

chrome.app.runtime.onLaunched.addListener(function() {
    chrome.app.window.create('index.html', {
        'bounds': {
            'width': window.screen.availWidth*0.8, // *0.8 is not working
            'height': window.screen.availHeight*0.8
        }
    });
});

最佳答案

看来数字必须四舍五入,因为无法处理许多小数:

chrome.app.runtime.onLaunched.addListener(function() {
    chrome.app.window.create('index.html', {
        'bounds': {
            'width': Math.round(window.screen.availWidth*0.8),
            'height': Math.round(window.screen.availHeight*0.8)
        }
    });
});

关于background - 如何设置 Chrome 应用程序相对于屏幕的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19204517/

相关文章:

c++ - ifstream 缓冲区限制/溢出? C++ (_cnt?)

sql - SQL Server 数据库 'optimizing' 索引的奇怪结果,原因是什么?

HTML5 文件系统 - 将文件保存在磁盘上

Java:如何在后台记录击键?

wpf - 如何在 WPF 中更改 TextBox 的禁用背景颜色

Android 4 条尺寸(Galaxy Nexus)

javascript - Chrome 打包应用程序和 Chrome 扩展程序之间进行通信?

WebRTC 和 Google Chrome 应用程序 - 麦克风音量调节

objective-c - iOS 在后台代码中运行计时器

android - 在 android 屏幕上插入移动图像作为背景