简体   繁体   English

为什么 OnBeforeUnload 没有拦截我的 GWT 应用程序中的后退按钮?

[英]Why the OnBeforeUnload doesn't intercept the back button in my GWT app?

I have a hook on the beforeUnload event.我在 beforeUnload 事件上有一个钩子。 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 :在 html 的开头:

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

And i use the Gwt PlaceHistoryMapper.我使用 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.只要你留在你的应用程序中,因为它是一个单页应用程序,它不会根据定义unload ,所以没有beforeunload事件。

When using Places , the equivalent is the PlaceChangeRequestEvent dispatched by the PlaceController on the EventBus .使用Places 时,等效的是由PlaceChangeRequestEventPlaceController上调度的EventBus This event is also dispatched in beforeunload BTW, and is the basis for the mayStop() handling in Activities .此事件也在beforeunload BTW 中调度,并且是活动中mayStop()处理的基础。

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 ).在 GWT 之外,在 JS 世界中,等效项将是hashchange和/或popstate ,具体取决于您的PlaceHistoryHandler.Historian实现(默认使用History.newItem() ,因此将是hashchange )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM