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

编程入门 行业动态 更新时间:2024-10-24 10:14:52
本文介绍了为什么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应用程序中的后退按钮?

本文发布于:2023-11-24 18:51:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1626414.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   按钮   OnBeforeUnload   GWT

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!