为什么OnBeforeUnload不拦截我的GWT应用程序中的后退按钮? [英] Why the OnBeforeUnload doesn't intercept the back button in my GWT app?

查看:105
本文介绍了为什么OnBeforeUnload不拦截我的GWT应用程序中的后退按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在beforeUnload事件上有一个钩子。如果我尝试点击链接,重新加载或关闭标签或导航器,应用程序在离开前请求确认。这是所期望的行为。



但是,如果点击后退按钮或输入外的退格键,则无法确认。



pre $ window.onbeforeunload = function(){
if(confirmEnabled)
返回;
}

我使用Gwt PlaceHistoryMapper。

我错过了什么?

谢谢!

解决方案

只要你留在你的应用程序中,因为它是一个单页面应用程序,它不会按照定义卸载,所以没有 beforeunload code> event。



使用 Places 时,相当于 PlaceChangeRequestEvent PlaceController EventBus 中分派。这个事件分配在 beforeunload 顺便说一句,并且是 mayStop()在 中处理。



外部GWT,在JS世界中,相当于 hashchange 和/或 popstate ,具体取决于 PlaceHistoryHandler.Historian 的实现(默认的使用 History.newItem(),所以这将是 hashchange )。


I have a hook on the beforeUnload event. If i try to click on a link, reload or close the tab or the navigator, the app ask for confirmation before leaving. That's the desired behavior.

But if click on the back button or the backspace outside an input, no confirmation.

At the beginning of the html :

window.onbeforeunload = function() {
 if (confirmEnabled)
    return "";
}

And i use the Gwt PlaceHistoryMapper.

What did i miss ? Where did i forgot to look ?

Thanks !

解决方案

As long as you stay within your app, because it's a single-page app, it doesn't by definition unload, so there's no beforeunload event.

When using Places, the equivalent is the PlaceChangeRequestEvent dispatched by the PlaceController on the EventBus. This event is also dispatched in beforeunload BTW, and is the basis for the mayStop() handling in Activities.

Outside GWT, in the JS world, an equivalent would be hashchange and/or popstate, depending on your PlaceHistoryHandler.Historian implementation (the default one uses History.newItem(), so that would be hashchange).

这篇关于为什么OnBeforeUnload不拦截我的GWT应用程序中的后退按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆