To detect when a user moves back in a web browser

Asked 1 years ago, Updated 1 years ago, 45 views

I want to give you an alert when the user goes back in the web browser.

How can I detect it when I go backwards?

html5 jquery javascript

2022-09-22 22:12

1 Answers

I solved it as below.

window.onbeforeunload = function(e) {
  if ($('.form').val()) {
    There is a post that is being created 'return'.';
  }
};

If you try to leave the page while you are creating in the form, an alert appears.


2022-09-22 22:12

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.