0

I have a table where by clicking any row I can access context menu

<tr oncontextmenu="return showContextMenu(event,'@item.SomeValue')"  style="cursor: pointer;">

The event of showing the context menu looks like this:

var contextMenu = document.getElementById('contextMenu');

 function showContextMenu(event, elemId) {
            contextMenu.style.display = 'block';
            contextMenu.style.left = (event.pageX - 220) + 'px';
            contextMenu.style.top = (event.pageY - 48) + 'px';
        }

and event of closing context menu this way:

window.onclick = hideContextMenu;
function hideContextMenu() {
    contextMenu.style.display = 'none';
}

The context menu looks like this:

<div id="contextMenuPasta" class="contextMenu" >
    <ul>
        <li  id="renomearCMid" data-toggle="modal" data-target="#modalRenomearPasta"><span><i class="fa fa-fw fa-pencil" ></i> Renomear Pasta</span></li>
        <li  id="removerCMid"  data-toggle="modal" data-target="#modalExcluirPasta"><span><i class="fa fa-fw fa-trash-o"></i> Remover Pasta</span></li>
        <li  id="adicionarCMid" data-toggle="modal" data-target="#modalNovaPasta"><span><i class="fa fa-fw fa-plus"></i> Adicionar Pasta</span></li>
    </ul>
</div>

Is there any way to change right click mouse to the left click, in order to show context menu? Thank You for help.

1 Answer 1

2

I solved the problem this way:

  1. in tr tag instead of using 'oncontextmenu' I used simply 'onclick'

  2. delete 'hideContextMenu' function

  3. instead, use this

    window.onclick = function (event) {
        if(event["path"][0].tagName != "TD" ){
            contextMenu.style.display = 'none';
        }
    };
    
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.