View Full Version : contextmenu not working

14 Jun 2010, 2:22 AM
Hi All

I've written the following test code

<title>Getting Started Example</title>
<link rel="stylesheet" type="text/css" href="lib/extjs/resources/css/ext-all.css" />

<script src="js/yui/2/build/utilities/utilities.js"></script>
<script src="lib/extjs/adapter/yui/ext-yui-adapter.js"></script>
<script src="lib/extjs/ext-all-debug.js"></script>

Ext.get('myDiv').on('contextmenu', function(eventObj, elRef) {
alert('myDiv contextmenu Handler, source elment ID: ' + elRef.id);
<div id="myDiv" style="background-color:green"> MyDiv Text
<a href="#" oncontextmenu="alert('test'); Ext.stopEvent();">skdhksjdfkjsdhfh</a>

When I right-click the anchor, the alert message is shown. However, when I do the same thing with the div, nothing happens. Any suggestions why ?


14 Jun 2010, 6:50 PM
Even though this is not an really EXT JS, does oncontextmenu work on div directly? If it does, you still need to use "oncontextmenu" even though you are calling the on() method. The event that fires will be "oncontextmenu", not "contextmenu"

14 Jun 2010, 9:27 PM
Event names do not contain "on". Think about it. The event is, logically, "contextmenu".

The handler might be called onContextMenu, but how can an event contain "on"? It's not logical. Oh! McSoft did it, so....

15 Jun 2010, 6:16 AM
I know they don't contain "on" in the context of EXT JS. Neither is it past tense. You are right Animal, it makes no sense to have "on".

Sorry that was the wrong help.

You are getting some syntax errors... Namely, you didn't close off onReady(), and I am not sure if you need to reference "ext-base.js"

15 Jun 2010, 12:27 PM
you're right. It was an syntax error which I missed, sorry!