my Apps: * COOL MOVIE BROWSER (sports, tv on net) here * MONEY ON THREAD (personal finance) here * HIT-BALL (cute game) here



GXT (Ext GWT) - How can I disable the browser's default right click response?

1. Using the GXT (Ext GWT) library from the ExtJS is very simple.

You can write a static function like this:
/**
* Disable the browser's default right click response.
*/
public static void disableDefaultContextMenu() {
Document.get().addListener(Events.OnContextMenu,
new Listener() {
public void handleEvent(ComponentEvent be) {
be.preventDefault();
}
});
Document.get().sinkEvents(Event.ONCONTEXTMENU);
}

and you call it first thing in your "onModuleLoad()" function.

Now, all default right-click menus are gone, and only the ones defined by your application will appear.

2. For pure GWT implementation try this:
- first define the static function:
/**
* Returns the document element.
*/
public static native com.google.gwt.user.client.Element getDocElement() /*-{
return $doc;
}-*/;

- and then call this code first thing in the "onModuleLoad()":
Event.addNativePreviewHandler(new Event.NativePreviewHandler(){
@Override
public void onPreviewNativeEvent(NativePreviewEvent event) {
if (event.getTypeInt() == Event.ONCONTEXTMENU){
event.getNativeEvent().preventDefault();
}
}
});
DOM.sinkEvents(getDocElement(), Event.ONCONTEXTMENU);


I hope you'll be happy after that...

Cheers!

1 comment:

  1. I’m not sure where you are getting your info, but great topic. I need to spend some time learning much more or understanding more. Thanks for fantastic information.
    website design

    ReplyDelete