8 Jul 2007 bkode   » (Master)

IE JS hack :Catching the Maximise / Minimise event

Here's a little hack to find out whether the user has maximised or minimised the window .This can then be used to trigger other useful chain of events of your choice .

Explanation:
The screenX, and screenY properties of the event corresponds to the the x and y coordinates of the mouse pointer's position relative to the user's screen respectively .

Now comes the juicy part ....

IE forces a mouse move whenever you change the focus of the window .So the interesting point to note is that - a mousemove event is forced even though the mouse co-ordinates dont actaully move ! So if you are able to track the previous mouse co-ords and catch the point where a mouse move is called - but at the same time the values dont change - bingo ! 8 )




var logs ,x=-1, y=-1 ,ctr = 2;
document.onmousemove = catchmaxmin;

function catchmaxmin(ev){
logs = document.getElementById('logs');
var e = (ev!=undefined)?ev:event;
if(e["screenX"]==x && e["screenY"]==y && ctr%2==0 ){
logs.innerHTML+= '
maximized /minimized ! ';
}
ctr++;
x = e["screenX"];
y = e["screenY"];
}


I've been looking for a similiar hack in firefox ,but i guess this useful bug has'nt been introduced into the Mozilla camp . 8 ) Here's a working demo ( tested on ie6 , ie7 ) of the 10 odd lines of code needed .

Keep Clicking,
Bhasker V Kode

Technorati Tags: javascript, event, maxmin, ie, window, bosky101, bhasker, kode, hack

The Returnable Project - Whats your return type ?...Enabling in-text content into your blog

Syndicated 2007-04-12 08:06:00 (Updated 2007-04-12 08:28:53) from Bosky says........the web log of Bhasker V K

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!