【问题标题】:Code for how to prevent user from refreshing the page either by using refresh button of browser or CTRL+F5 in angular js [duplicate]如何通过使用浏览器的刷新按钮或 Angular js 中的 CTRL+F5 来防止用户刷新页面的代码 [重复]
【发布时间】:2018-11-23 01:52:33
【问题描述】:

关于如何防止用户通过使用浏览器的刷新按钮或 Angular js 中的 CTRL+F5 来刷新页面的代码

【问题讨论】:

  • 你不能。为什么要阻止它?
  • 因为该页面保存了表单数据,用户可能会不小心刷新页面
  • 保存在localstorage
  • 您是否在询问如何使“请确认您要离开页面”对话框就像您在编写答案时尝试刷新时得到的那样?

标签: angularjs


【解决方案1】:

你不能停止手动刷新页面的用户表单,这也不是一个好的用户体验。相反,您可以要求确认页面重新加载。在 JS 中,我们使用 window.onbeforeunload 来处理这个问题:

window.onbeforeunload = function() {
    return "Your form progress will be lost, are you sure you want to reload this page?";
}

This reference shows you how to achieve this in Angular Js

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2012-08-31
  • 2020-12-25
  • 2011-09-13
  • 1970-01-01
  • 2018-01-09
  • 1970-01-01
相关资源
最近更新 更多