Raveendra Pai U
Raveendra Pai U

Reputation: 135

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?

Upvotes: 0

Views: 121

Answers (1)

JJ_
JJ_

Reputation: 174

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 e.g.

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);

Upvotes: 1

Related Questions