-1

I have a div and on mouseover I show an ice:menuPop with this function:

function fireContextMenu(element, event) {
   if (element.getAttribute('oncontextmenu')) {
      element.oncontextmenu = new Function ('event', element.getAttribute('oncontextmenu'));
      element.oncontextmenu(event);
   }
}

calling it like:

onmouseover="fireContextMenu(this, event);"

On Chrome is working perfect but on IE it does not appears. I suppose it's something wrong in the js or IE8 does not support hover of div?

Yi Jiang
  • 49,435
  • 16
  • 136
  • 136
Cristian Boariu
  • 9,603
  • 14
  • 91
  • 162
  • 1
    As an aside, have a look at this: http://stackoverflow.com/questions/259614/unobtrusive-javascript-with-jquery-good-10-minute-tutorial – joshcomley Feb 23 '11 at 13:38
  • 1
    Icefaces *shudders*.... `new Function` *screams* – Ivo Wetzel Feb 23 '11 at 13:39
  • 2
    So, every time the mouse moves over your element, you want to to set the "oncontextmenu" attribute to a new function ... really? Do you think this will work the second time the mouse moves over the element? – Pointy Feb 23 '11 at 13:40
  • 1
    `getAttribute` is hideously broken unless you are using IE8 Standards Mode. This doesn't have a hope if you are in Quirks mode or IE 7 Compatibility Mode. `getAttribute` is best avoided in favour of direct property accessors. – Quentin Feb 23 '11 at 13:40
  • @Pointy: yeah, it's working. If you can suggest a better way I'd appreciate it. – Cristian Boariu Feb 23 '11 at 13:44
  • Hmm if it's working it's probably because the function established in the previous call is converted back to a string and then re-made into a new function. – Pointy Feb 23 '11 at 14:12
  • the single problem I see now is how to get onContextMenu value in IE? so a workaround for this: element .getAttribute('oncontextmenu') would be welcome... – Cristian Boariu Feb 23 '11 at 14:23

1 Answers1

0

Solved.

No longer use the js function but use directly the value of oncontextmenu.

For my case:

onmouseover="Ice.Menu.contextMenuPopup(event, 'frmMainMenu:menuPopupCBM_sub', 'frmMainMenu:divMenuPopupCBM');return false;"
Cristian Boariu
  • 9,603
  • 14
  • 91
  • 162