最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Confirm browser back button else stay on page - Stack Overflow

programmeradmin3浏览0评论

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

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

Share Improve this question asked Sep 9, 2010 at 22:46 Stephen WayStephen Way 6783 gold badges7 silver badges20 bronze badges 1
  • 1 See [ How can I override the OnBeforeUnload dialog and replace it with my own? ](stackoverflow./questions/276660/…). The bottom line is that the only flexibility for this dialog is adding a string. This is for security reasons. – Matthew Flaschen Commented Sep 9, 2010 at 22:53
Add a ment  | 

1 Answer 1

Reset to default 12

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.

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?";
}
发布评论

评论列表(0)

  1. 暂无评论