如何在Chrome扩展中设置当前窗口的宽度? [英] How to set current window's width, in chrome extension?

查看:774
本文介绍了如何在Chrome扩展中设置当前窗口的宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Chrome扩展。

我试图获取当前窗口,然后设置它的宽度,但它不起作用吗?



以下是background.js中的代码:

  chrome.windows.getCurrent(
{populate:false},
函数(currentWindow){
currentWindow.width = 500;
}
);

回答manifest.json:

 {
name:windowresizer,
description:调整当前窗口的大小!,
version:1.0,
manifest_version:2,
background:{
scripts:[background.js],
persistent:false
},
permissions:[tabs]
}

't work?

解决方案

您需要使用 chrome.windows.update
$ p $ chrome.windows.getLastFocused(
{populate:false},
function( currentWindow){
chrome.windows.update(currentWindow.id,{width:500});
}
);


I'm developing a chrome extension.
I tried to get the current window then set its width, but it doesn't work ?

Here's the code in background.js:

chrome.windows.getCurrent(
    {populate: false}, 
    function(currentWindow) {
        currentWindow.width = 500;
    }
);

Ans here's the manifest.json:

{
    "name" : "windowresizer",
    "description" : "resize current window !",
    "version" : "1.0",
    "manifest_version" : 2,
    "background" : {
        "scripts" : ["background.js"],
        "persistent" : false
    },
    "permissions" : ["tabs"]
}

Why it doesn't work ?

解决方案

You need to use the chrome.windows.update function:

chrome.windows.getLastFocused(
    {populate: false}, 
    function(currentWindow) {
        chrome.windows.update(currentWindow.id, { width: 500 });
    }
);

这篇关于如何在Chrome扩展中设置当前窗口的宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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