-1

I am working an application where each time the user open the page atomatically genrate an id for that page using the database. All data is stored with that id when the user click save button (the saving button in a server side ) . But how I can do that, If the user click the go back or close buttons in the brower I want a window appear with some text like "You forget to click save button to save your work , If you leave you will lose your work!". In the same time I want to delete the id if the user did not click save button and leave the page.

  • 1
    Possible duplicate of [How to show the "Are you sure you want to navigate away from this page?" when changes committed?](https://stackoverflow.com/questions/1119289/how-to-show-the-are-you-sure-you-want-to-navigate-away-from-this-page-when-ch) – SᴇM Dec 08 '17 at 10:06

1 Answers1

0
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

     <script type="text/javascript">
        jQuery(document).ready(function ($) {

            if (window.history && window.history.pushState) {

                window.history.pushState('forward', null, './#forward');

                $(window).on('popstate', function () {
                    alert('hey wait You Clicked Back Button');
                    //your Code here

                });

            }
        });
     </script>
ArunPratap
  • 4,816
  • 7
  • 25
  • 43