简体   繁体   中英

Extension notification when there is change in browser window size

I've developed a Firefox extension that needs to be notified whenever there is a change in the browser window size.

I used gBrowser.addeventListener("resize",my_funcion,false); in my .js file of extension. But this will be notified very frequently when you change the browser window size by dragging. I require the final value of window parameter after resize is done, not during resize.

Which event should I register to do this?

Does the gBrowser.addeventListener("resize", attach a resize listener to the window or the tabbrowser? I always thought gBrowser was a shortcut to the tabbrowser element.

When I've had to listen to window resize events, a queue system seemed like the best option eg

var queue=0;
var chromeWinOuterHeight;
var timer = Components.classes["@mozilla.org/timer;1"].createInstance(Components.interfaces.nsITimer);

function chromeWinResize(e){
    queue++;
    timer.initWithCallback(function(){
        if(queue>1){
            queue--;
        }
        else if(chromeWinOuterHeight !== e.target.outerHeight){
            //do stuff
        }
        chromeWinOuterHeight = e.target.outerHeight;
    }, 500, Components.interfaces.nsITimer.TYPE_ONE_SHOT);
};
chromeWindow.addEventListener('resize',chromeWinResize,false);

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