Entry
Can I check whether a window is moved?
Is there a window.onmove handler?
Mar 10th, 2001 15:32
Gil Barros, Martin Honnen, http://developer.netscape.com/docs/manuals/js/client/jsref/handlers.htm#1120958
NN4 only provides a window.onmove handler, neither IE4/5 nor
NN6 (at the time of writing this) support it. The handler fires both
when the user moves the window and when js moves the window.
You can script it as follows
window.onmove = function (evt) {
alert(evt.type);
}
to just check it works or e.g.
window.onmove = function (evt) {
window.status = window.screenX + ':' + window.screenY;
}
A workaround for the missing window.onmove in IE and NN6 is
the following which uses setInterval to periodically check the
window coordinates
Limitation: the window.screenLeft and window.screenTop
properties return undefined when on IE/Mac (a bug?), so the
workaround doesn't work there...
<HTML>
<HEAD>
<TITLE>
window.onmove replacement for NN6 and IE4+
</TITLE>
<SCRIPT>
if (!document.layers) {
var oldScreenX =
document.all ? window.screenLeft : window.screenX;
var oldScreenY =
document.all ? window.screenTop : window.screenY;
var tid = setInterval('checkMove()', 100);
}
function checkMove () {
var curScreenX =
document.all ? window.screenLeft : window.screenX;
var curScreenY =
document.all ? window.screenTop : window.screenY;
if (curScreenX != oldScreenX || curScreenY != oldScreenY) {
// put code here to call in window.onmove
alert('moved');
}
oldScreenX = curScreenX;
oldScreenY = curScreenY;
}
</SCRIPT>
</HEAD>
<BODY ONLOAD="window.resizeBy(-10, -10);
window.moveBy(10,10);">
</BODY>
</HTML>