javascript - How to set current window's width, in chrome extension? - Stack Overflow

admin2025-04-20  0

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 ?

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 ?

Share Improve this question asked Sep 25, 2013 at 14:24 Ashraf BashirAshraf Bashir 9,80415 gold badges60 silver badges83 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

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

chrome.windows.getLastFocused(
    {populate: false}, 
    function(currentWindow) {
        chrome.windows.update(currentWindow.id, { width: 500 });
    }
);
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745084682a284066.html

最新回复(0)