Andrei Stanca
Andrei Stanca

Reputation: 908

how to call jquery contextmenu on left-click?

I am using this contextmenu plugin: http://abeautifulsite.net/blog/2008/09/jquery-context-menu-plugin/

DEMO: http://labs.abeautifulsite.net/projects/js/jquery/contextMenu/demo/

SOURCE-CODE: http://labs.abeautifulsite.net/projects/js/jquery/contextMenu/demo/jquery.contextMenu.js

DEFAULT CALL:

$("#myDiv").contextMenu({
                    menu: 'myMenu'
                },
                    function(action, el, pos) {
                    alert(
                        'Action: ' + action + '\n\n' +
                        'Element ID: ' + $(el).attr('id') + '\n\n' + 
                        'X: ' + pos.x + '  Y: ' + pos.y + ' (relative to element)\n\n' + 
                        'X: ' + pos.docX + '  Y: ' + pos.docY+ ' (relative to document)'
                        );
                });

I want to call this context menu on a left click rather than a right click, how can I achieve this ? or any other plugin suggestions?

Upvotes: 1

Views: 1971

Answers (2)

Naftali
Naftali

Reputation: 146310

Do a regular click handler:

$("#myDiv").on('click', function() {
    $(this).contextmenu(...)
})

Upvotes: 1

Tony C.H. Liu
Tony C.H. Liu

Reputation: 11

Inside the source code, looking for the following codes:

if( evt.button == 2 ) {...

According to W3C its values should be:

Left button = 0,

Middle button = 1,

Right button = 2,

According to Microsoft its values should be:

Left button = 1,

Middle button = 4,

Right button = 2,

You may change the value depending on what you need.

Upvotes: 0

Related Questions