ExtJS : How to disable browser context menu 3
Feb11
This is a quick solution to disabling browser default context menu when right-clicking in ExtJS.
Ext.getBody().on("contextmenu", Ext.emptyFn, null, {preventDefault: true});
Basically, you can implement a TreePanel or other ExtJS components like:
new Ext.tree.TreePanel({
listeners: {
render: function() {
// After the component has been rendered, disable the default browser context menu
Ext.getBody().on("contextmenu", Ext.emptyFn, null, {preventDefault: true});
},
contextmenu: function(e) {
// Init your context menu
}
}
});
Tested working on FF 3.6, Chrome 3, Safari 4 and IE7. Opera 10 unfortunately fails.









Genial post and this enter helped me alot in my college assignement. Thank you on your information.
thx for this useful tip. If you put this statement in the onReady function it disables the browsers contextmenu (= “right-click” menu) completely on your page.
Regarding implementing your own contextmenu: it is slightly more involved than the few lines above, but the API documentation has a very clear example.
@rblon: Yeah, what do you mean the API doc has examples on ? What I meant here is we can init our own ExtJs Context Menu.. after disabling the browser default one..