有没有办法在GWT中禁用浏览器中的后退按钮(基本上清除历史记号栈)?一旦我浏览到应用程序中的某个页面,我想确保用户不能使用后退按钮返回,但只能使用页面上的链接来浏览网站。禁用GWT中的后退按钮
2
A
回答
6
你不能禁用一个按钮只是截取它,并将其返回值改变为浏览器不理解的东西。
这消除了历史:
Window.addWindowClosingHandler(new ClosingHandler() {
@Override
public void onWindowClosing(ClosingEvent event) {
event.setMessage("My program");
}
});
不过,我建议不这样做,因为你它违背了优秀的用户界面的做法。相反,您应该找出后退按钮不会导致代码出现问题的方式。
0
Window.addWindowClosingHandler(new ClosingHandler() {
@Override
public void onWindowClosing(ClosingEvent event) {
event.setMessage("My program");
}
});
这不是一个傻瓜证明的解决方案。在火狐中,我可以按下后退按钮,并且绝不会调用方法onWindowClosing
。原因是我使用了History.newItem()
,并且由于历史记录存在后退按钮或退格按钮,因此只需浏览浏览器历史记录即可。
所以....修复:)
1
我发现了一个方法,使GWT忽略后退按钮:只需添加historyitem x如果没有historyitem设置并做X什么。
历史的ValueChangeHandler设置historyitem上启动
History.newItem("x")
添加以下内容:
String historyToken = event.getValue(); if (!historyToken.equals("x")) History.newItem("x");
0
在index.html文件
将这个window.open(' html页面(例如trial.html)','所需站点的名称',width ='你想要的',height ='你想要的',centerscreen = yes,menubar = no,toolbar = no,location = no , personalbar = no,directories = no,status = no,resizable = yes,dependent = no,titlebar = no,dialog = no');
2
请拨打以下onModuleLoad()
中的方法。
private void setupHistory() {
final String initToken = History.getToken();
if (initToken.length() == 0) {
History.newItem("main");
}
// Add history listener
HandlerRegistration historyHandlerRegistration = History.addValueChangeHandler(new ValueChangeHandler() {
@Override
public void onValueChange(ValueChangeEvent event) {
String token = event.getValue();
if (initToken.equals(token)) {
History.newItem(initToken);
}
}
});
// Now that we've setup our listener, fire the initial history state.
History.fireCurrentHistoryState();
Window.addWindowClosingHandler(new ClosingHandler() {
boolean reloading = false;
@Override
public void onWindowClosing(ClosingEvent event) {
if (!reloading) {
String userAgent = Window.Navigator.getUserAgent();
if (userAgent.contains("MSIE")) {
if (!Window.confirm("Do you really want to exit?")) {
reloading = true;
Window.Location.reload(); // For IE
}
}
else {
event.setMessage("My App"); // For other browser
}
}
}
});
}
相关问题
- 1. 后退按钮禁用
- 2. 禁用后退按钮
- 3. 禁用IE后退按钮
- 4. Android禁用后退按钮
- 5. Response.Redirect()禁用后退按钮
- 6. Response.Redirect禁用后退按钮
- 7. IOS 9.3禁用iPhone上的后退按钮后退按钮
- 8. 禁用Angular4中的后退按钮Cordova
- 9. 在WizarDroid中禁用后退按钮
- 10. 退出后在laravel中禁用浏览器的后退按钮
- 11. 如何禁用Android的后退按钮#
- 12. 如何禁用inappbrowser的后退按钮?
- 13. 禁用和启用后退按钮
- 14. 后退按钮似乎已禁用iOS
- 15. 禁用浏览器后退按钮javascript
- 16. 暂时禁用后退按钮
- 17. 如何禁用注销后退按钮?
- 18. 如何jquerymobile禁用后退按钮
- 19. Android - 禁用设备后退按钮
- 20. Flex Air Android:禁用后退按钮
- 21. 禁用后退主页按钮Android 3.1
- 22. 禁用后退按钮文本
- 23. Android DroidGap禁用后退按钮
- 24. 如何禁用后退按钮行为?
- 25. 禁用机器人后退按钮
- 26. 电梯禁用后退按钮操作
- 27. 后退按钮在javascript禁用问题
- 28. GWT后退按钮浏览器
- 29. 如何禁用在android中按下webview的后退按钮?
- 30. 应用按后退按钮当按下后退按钮
如果你必须禁用后退按钮,你做错了。编写良好的Ajax工具包旨在正确处理后退按钮(以便他们将调用应用程序的回调---与单击导航链接的效果相同)。 – 2010-03-05 18:20:31
有很多关于此重复:http://stackoverflow.com/questions/1864706/disable-back-button/1864709#1864709,http://stackoverflow.com/questions/961188/disable-browsers-back-按钮 – 2010-03-05 18:21:09
@迈克尔:是的,仍然与“不要”的基本信息 - 应该是。 :-) @OP:请参阅http://www.useit.com/alertbox/990530.html,第1项。 – 2010-03-05 18:24:40