问题
This works great in Chrome, but what do I need to change to make it work in Firefox?
e.ctrlKey remains false in FF:
$('img').on('drag', function(e){
console.log('ctrlKey', e.ctrlKey);
});
http://jsfiddle.net/YF6UG/4/
回答1:
I think this is a bug in Firefox. After some digging in Bugzilla I found unconfirmed bug similar to your problem titled DragEnd event does not reflect real ctrl/shift/alt key status.
回答2:
It seems you can detect the ctrlKey in startdrag event, so as a workaround, you can just $(event.dataTransfer.setData('ctrlKey',event.ctrlKey) in startdrag. Then you can read it by $(event.dataTransfer.getData('ctrlKey') inside dragEnd event
来源:https://stackoverflow.com/questions/24016457/html5-image-drag-event-ctrlkey-remains-false-in-firefox-29