Window.onmousemove in IE and Firefox

The purpose of the following code is that when the user holds the SHIFT key, some text will indicate that they are clicking on it. It works fine in Firefox, but IE does not confirm 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.

+6
javascript javascript-events
source share
1 answer

Despite what MSDN says, onmousemove does not work when applied to a window object. It should work in all browsers if you apply it to the document object:

 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/

+16
source share

All Articles