Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capture mouseup event outside of browser/window

Right now I'm stopping drag events on mouse up, like so:

$(document).mouseup(_onMouseUp);

However I need to capture mouse up events when the mouse leaves the browser window, similar to releaseOutside in Flash.

Is this possible in JS?

like image 216
Nick Jonas Avatar asked Jan 18 '13 21:01

Nick Jonas


1 Answers

You can capture mouseup events outside the browser window in every major browser: Chrome, Edge and Firefox.

You just need to attach the listener to the 'window' object, like this:

window.addEventListener('mouseup', 
                         () => console.log('mouse up captured outside the window'));

https://codepen.io/fredrikborgstrom/pen/vRBaZw

or in your case, using jQuery, it would be:

$(window).mouseup(_onMouseUp);
like image 192
Fredrik_Borgstrom Avatar answered Oct 20 '22 00:10

Fredrik_Borgstrom