How to detect if the user clicked the “back” button

后端 未结 5 625
说谎
说谎 2020-11-29 06:41

When the user goes history-back-1...how do I detect that? And then, alert \"the user clicked back!\"

Using binds (and jQuery preferably)

5条回答
  •  南笙
    南笙 (楼主)
    2020-11-29 07:17

    try:

    window.onbeforeunload = function (evt) {
      var message = 'Are you sure you want to leave?';
      if (typeof evt == 'undefined') {
        evt = window.event;
      }
      if (evt) {
        evt.returnValue = message;
      }
      return message;
    }
    

提交回复
热议问题