Is it possible to trigger the middle mouse click using Javascript?

I want to run the middle mouse click using javascript. Is it possible to trigger the middle mouse click using Javascript?

I want because it pastes the last selected object from the clipboard.

Thanks Jimit

+4
source share
2 answers

Had the same question, dug a lot, and here is what I ended up using:

if ( window.CustomEvent ) {
    var middleClick = new MouseEvent( "click", { "button": 1, "which": 1 });
    jQuery(".selector")[0].dispatchEvent( middleClick );
}
+3
source

you can use

event.button

to determine which mouse button was clicked.

Returns an integer value indicating the button that changed the state.

* 0 for standard 'click', usually left button
* 1 for middle button, usually wheel-click
* 2 for right button, usually right-click

  Note that this convention is not followed in Internet Explorer: see 
  QuirksMode for details.

The order of the buttons may vary depending on how the pointing device is configured.

Also read

Which mouse button was clicked on?

: . , . , .

-1

Source: https://habr.com/ru/post/1530547/


All Articles