Article written

  • on 11.02.2010
  • at 01:06 AM
  • by admin

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.

http://iamtotti.com/blog/wp-content/plugins/sociofluid/images/digg_24.png http://iamtotti.com/blog/wp-content/plugins/sociofluid/images/reddit_24.png http://iamtotti.com/blog/wp-content/plugins/sociofluid/images/stumbleupon_24.png http://iamtotti.com/blog/wp-content/plugins/sociofluid/images/delicious_24.png http://iamtotti.com/blog/wp-content/plugins/sociofluid/images/technorati_24.png http://iamtotti.com/blog/wp-content/plugins/sociofluid/images/google_24.png http://iamtotti.com/blog/wp-content/plugins/sociofluid/images/facebook_24.png http://iamtotti.com/blog/wp-content/plugins/sociofluid/images/yahoobuzz_24.png http://iamtotti.com/blog/wp-content/plugins/sociofluid/images/twitter_24.png

subscribe to comments RSS

There are 3 comments for this post

  1. WP ThemesNo Gravatar says:

    Genial post and this enter helped me alot in my college assignement. Thank you on your information.

  2. rblonNo Gravatar says:

    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.

  3. adminNo Gravatar says:

    @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.. :)

Please, feel free to post your own comment

* these are required fields