How do make the browser back trigger with GWT, when the mouse cursor is not on a text input or text area?
However when its on a text input or text area, pressing back should function as a text backspace and not trigger browser back?
Something like this should work. Just call the register method in order to set a the listener.
import com.google.gwt.dom.client.Element;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.Event.NativePreviewEvent;
import com.google.gwt.user.client.Event.NativePreviewHandler;
import com.google.gwt.user.client.History;
public class BackPreviewHandler implements NativePreviewHandler {
private HandlerRegistration handlerRegistration;
@Override
public void onPreviewNativeEvent(final NativePreviewEvent event) {
if (event.getTypeInt() == Event.ONKEYDOWN) {
if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_BACKSPACE) {
Element elemPointedByMouse = Element.as(event.getNativeEvent().getEventTarget());
String tagName = elemPointedByMouse.getTagName();
System.out.println(tagName);
if (!tagName.equalsIgnoreCase("INPUT")
&& !tagName.equalsIgnoreCase("TEXTAREA")) {
History.back();
}
}
}
}
public void register() {
handlerRegistration = Event.addNativePreviewHandler(this);
}
public void deregister() {
handlerRegistration.removeHandler();
}
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다