最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览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 });
    }
);
发布评论

评论列表(0)

  1. 暂无评论