简体   繁体   中英

Chrome Extension to Resize Window

I am trying to make an insanely simple Chrome extension. All I want is the following: a "browser_action" toolbar icon that when clicked either does one of the following (either is fine):

  • Displays a popup with a link that says "Full Screen" and clicking the link resizes the chrome window to the full size of the screen. (preferable)
  • Simply makes the screen full sized by clicking the toolbar icon itself. (still ok)

This should be easy, I've made chrome extensions before but I can't get it to work. Everytime I try to use the chrome.windows api from either my popup.html, a js included in popup.html, or something similar Chrome simply blocks be from doing anything. I even tried injecting code into a dummy tab like this:

chrome.browserAction.onClicked.addListener(function(tab) {
var bkg = chrome.extension.getBackgroundPage();
chrome.tabs.create({url: "http://www.google.com"}, function(tab) {
    chrome.tabs.executeScript(tab.id, {file: "newtab.js"}, function() {
        //Callback
    });
});

});

Where app.js contains the chrome.windows code to resize the window. And every time I get nothing. I have "permissions" : ["tabs","http://*/*", "https://*/*"] but I still can't do this very simple task. Ideas?

I was using Chrome 19, updated to 26 and it works. Windows API must have been added somewhere in between Full screen would look something like this (in a background script):

chrome.windows.getCurrent(function(wind) {
alert(wind.id);
var maxWidth = window.screen.availWidth;
var maxHeight = window.screen.availHeight;
var updateInfo = {
    left: 0,
    top: 0,
    width: maxWidth,
    height: maxHeight
};
chrome.windows.update(wind.id, updateInfo);});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM