1

我在 beforeUnload 事件上有一个钩子。如果我尝试单击链接、重新加载或关闭选项卡或导航器,应用程序会在离开前要求确认。这是期望的行为。

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

在 html 的开头:

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

我使用 Gwt PlaceHistoryMapper。

我错过了什么 ?我忘了看哪里?

谢谢 !

4

1 回答 1

2

只要你留在你的应用程序中,因为它是一个单页应用程序,它不会被定义为unload,所以没有beforeunload事件。

当使用Places时,等价于由onPlaceChangeRequestEvent调度的。这个事件也在BTW 中被调度,并且是在Activities中处理的基础。PlaceControllerEventBusbeforeunloadmayStop()

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

于 2012-11-13T10:46:02.720 回答