Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

I want it because it is pasting last selected object from clipboard.

Thanks, Jimit

like image 400
Jimit Avatar asked Mar 07 '14 07:03

Jimit


People also ask

How to detect mouse click event in JavaScript?

The MouseEvent button property is used to define the left or right click events. When mouse button is clicked then it return an integer value which describe the left, right or middle mouse button. Return Value: This event return an integer value on mouse click events are: 0: It indicates the left mouse button.

How do you scroll with middle click?

Many mice and some touchpads have a middle mouse button. On a mouse with a scroll wheel, you can usually press directly down on the scroll wheel to middle-click. If you don't have a middle mouse button, you can press the left and right mouse buttons at the same time to middle-click.

How click event works?

An element receives a click event when a pointing device button (such as a mouse's primary mouse button) is both pressed and released while the pointer is located inside the element.

What is middle click scroll called?

"auto-scroll", "Auto-scrolling is a feature that can be found in most mainstream modern applications. Pressing the middle mouse button transfers the application into the auto-scrolling mode.


1 Answers

Had the same question, did a lot of digging, and this is what I ended up using:

if ( window.CustomEvent ) {
    var middleClick = new MouseEvent( "click", { "button": 1, "which": 2 });
    jQuery(".selector")[0].dispatchEvent( middleClick );
}
like image 161
Mike Willis Avatar answered Oct 19 '22 14:10

Mike Willis