How to set current window's width, in chrome extension?

不打扰是莪最后的温柔 提交于 2019-12-13 03:23:26

问题


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 ?


回答1:


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

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


来源:https://stackoverflow.com/questions/19007606/how-to-set-current-windows-width-in-chrome-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!