如何在Chrome浏览器中调整窗口大小

如何在Chrome浏览器中调整窗口大小

问题描述:

我正在为chrome浏览器写一个扩展,我想为window resize事件添加事件监听器。

I am writing an extension for chrome browser where , I wanted to add event listener for the window resize event. I am getting my method executed for window load event , but not getting for resize event.

下面提到的是我的manifest.json文件的代码

Below mention is code for my manifest.json file

{
  "name": "A browser action",
  "version": "1.0",
  "background": { "scripts": ["background.js"] },
  "permissions": [
    "tabs", "http://*/*"
  ],
  "manifest_version": 2
}

下面提到的是我的background.js文件。

Below mention is code for my background.js file.

var myExtension = 
{  
    init: function()
    {  
      // The event can be DOMContentLoaded, pageshow, pagehide, load or   unload.           
      alert("ASHSIH");
      window.addEventListener("resize", this.onmyPageResize, false);
    },
    onmyPageResize: function(aEvent) 
    {  
      alert("RESIZED");

    }  
}


window.addEventListener("load", function load(event){  
  window.removeEventListener("load", load, false); //remove listener, no longer   needed  
  myExtension.init();    
},false); 


background.js文件无法捕获浏览器。您需要为此注入一个内容脚本

The background.js file cannot capture resize events in the browser. You would need to inject a content script for that.