window.onmousemove in IE and Firefox

12,177

Despite what the MSDN docs say, onmousemove doesn't work when applied to the window object. It should work in all browsers if you apply it to the document object instead:

document.onmousemove = function(e) {
    e = e || window.event;
    var copyLabel = document.getElementById("<%= lblCopyEnabled.ClientID %>");
    if (e.shiftKey) {
        copyLabel.style.display = "inline";
        ob_copyOnNodeDrop = true;
    }
    else {
        copyLabel.style.display = "none";
        ob_copyOnNodeDrop = false;
    }
}

Demo: http://jsfiddle.net/AndyE/aUxSz/

Share:
12,177

Related videos on Youtube

Honus Wagner
Author by

Honus Wagner

Blaaarrrrggghhhhh!

Updated on June 04, 2022

Comments

  • Honus Wagner
    Honus Wagner almost 2 years

    The purpose of the following code is that when the user is holding the SHIFT key down, some text will indicate that they are pressing it. It works great in Firefox, but IE does not acknowledge it.

    window.onmousemove = function(e) {
            e = e || window.event;
            var copyLabel = document.getElementById("<%= lblCopyEnabled.ClientID %>");
            if (e.shiftKey) {
                copyLabel.style.display = "inline";
                ob_copyOnNodeDrop = true;
            }
            else {
                copyLabel.style.display = "none";
                ob_copyOnNodeDrop = false;
            }
        }
    

    Advice is appreciated.