0

I want to have a contextmenu listening on a right-click on a specific cell.

In html file, I linked the Script by writing

<script src="ContextMenuController.js"></script> // link the js file
<link rel="stylesheet" type="text/css" href="ContextMenuStyle.css"> // link the css file

In my js-file i want to create this contextmenu by writing

$(this).closest('td').onmousedown = function(event) { // get the cell clicked on
    if (event.which == 3) { // just build the menu on a right click

      var contextElements = ["btnAddRowAbove", "btnAddRowBelow", "btnAddColumnLeft",
      "btnAddColumnRight", "btnMoveRowUp", "btnMoveRowDown", "btnMoveColumnLeft",
      "btnMoveColumnRight", "btnDeleteRow", "btnDeleteColumn", "btnUndo", "btnRedo"]; // store all the buttons of the menu

      var menuText = "<ul class=\"contextmenu\">"; // the wrapper
      for (var i = 0; i < contextElements.length; i++) {
        menuText += "<li id= contextElements[i]> contextElements[i] <\/li>"; // append all the buttons to the wrapper
      }
      return menuText + "<\/ul>"; // finish the wrapper
    }};

When i try to debug it with alert() the code does not even reach this function.

Could someone help me out?

Muhammad Faizan Uddin
  • 1,339
  • 12
  • 29
peterHasemann
  • 1,550
  • 4
  • 24
  • 56
  • Why don't you use `contextmenu` menu event? Attached it all `td`s and display the menu according to the position of the target. – Adam Azad Dec 14 '16 at 11:06
  • http://stackoverflow.com/questions/4495626/making-custom-right-click-context-menus-for-my-web-app – deChristo Dec 14 '16 at 11:13
  • Thanks for your answer! The fiddle helped me a lot. But when i finished the context menu i thought it would be better to have a ribbon. The context menu felt ... annoying... :/ – peterHasemann Dec 14 '16 at 14:40

0 Answers0