用户不友好onbeforeunload / onunload [英] user-unfriendly onbeforeunload / onunload

查看:129
本文介绍了用户不友好onbeforeunload / onunload的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力与onbeforeunload,onunload和在正确的时间生成正确的消息。任何想法欢迎。这是情况:




  • 当我使用onbeforeunload时,用户会收到一条消息来选择是否要离开,但是我不能转它关闭 - 消息是标准的,出现在事件处理程序中。

  • 当我使用onunload时,我可以控制发生的再见消息,但我无法为用户提供改变主意的机会。



    • 所以例如,如果有数据要保存。使用onbeforeunload,会弹出一个消息,无论用户的数据状态如何 - 询问是否要导航。使用onunload,我可以选择该消息,并在询问用户之前检查是否存在未保存的数据,如果已保存,请保存它们,但我的用户不能选择留在页面上。



      我错过了什么吗?看来我无法获得我想要的简单行为 - 检查应用程序状态,发送消息,并提供用户在离开之前采取行动。或者是使用这两种事件来获得这种行为?

      解决方案

      我为你做了一个简单的例子,我想想可以做你想要的不幸的是,没有办法更改 onbeforeunload 中的消息,但您可以在用户保存数据时删除该消息。 http://jsfiddle.net/JL48j/8/


      I'm struggling with onbeforeunload, onunload and generating the right messages at the right time. Any idea welcome. This is the situation:

      • when I use onbeforeunload, the user gets a message to choose whether to navigate away, but I can't turn it off - the message is standard and appears regardless what's in the event handler.
      • when I use onunload, I can control the "bye" messages that occur, but I cant offer the user the opportunity to change their mind.

      So for example, if there is data to save. With onbeforeunload, a message pops up, -regardless of the state of the user's data- asking if they want to navigate away or not. With onunload, I can choose the message and check whether there is unsaved data before asking the user, saving them the trouble if they have saved, but my user can't choose to stay on the page.

      Am I missing something there? It seems I can't get the simple behaviour I want - check application status, give a message, and offer the user to take action before they leave. Or is there a use of either or both events to get this behaviour?

      解决方案

      I made a simple example for you, that I think might do what you want. Unfortunately there is no way to change the message in onbeforeunload, but you can remove the message when the user saves data. http://jsfiddle.net/JL48j/8/

      这篇关于用户不友好onbeforeunload / onunload的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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