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!
Participant
No comments:
Post a Comment