确认浏览器后退按钮保留在页面上 [英] Confirm browser back button else stay on page

查看:95
本文介绍了确认浏览器后退按钮保留在页面上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在javascript或jquery中,当用户点击具有ok / cancel按钮模型的浏览器后退按钮时,我需要添加一个警告,但不是Ok,而应该说离开而不是取消它应该说保持。谢谢

In javascript or jquery I need to add an alert when the user clicks on the browser back button that has an ok/cancel button model, but instead of "Ok" it should say Leave and instead of Cancel it should say Stay. Thanks

推荐答案

您无法控制确认对话框按钮文本,它是 confirm() 并且是浏览器拥有的...不是你可以做很多事情。

You can't control the confirmation dialog button text, it's a hard coded feature of confirm() and is whatever the browser has...not much you can do about it.

对于实际的显示你可以使用 window.onbeforeunload ,但它赢了特定于后退按钮,任何离开页面的操作都会触发此操作,例如:

For the actual display you can use window.onbeforeunload, but it won't be specific to the back button, any action leaving the page will trigger this, for example:

window.onbeforeunload = function() {
  return "Are you sure you wish to leave this delightful page?";
}

这篇关于确认浏览器后退按钮保留在页面上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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