最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - window.onmousemove in IE and Firefox - Stack Overflow

programmeradmin1浏览0评论

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.

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.

Share Improve this question edited Jan 5, 2023 at 11:49 Brian Tompsett - 汤莱恩 5,88372 gold badges61 silver badges133 bronze badges asked Nov 23, 2010 at 15:49 Honus WagnerHonus Wagner 2,90813 gold badges45 silver badges61 bronze badges 1
  • What version of IE are you targeting? – stan229 Commented Nov 23, 2010 at 15:55
Add a comment  | 

1 Answer 1

Reset to default 19

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/

发布评论

评论列表(0)

  1. 暂无评论