Scroll to top

How to get warning when exit browser without saving?

Get warning when exit browser without saving

<script>
jQuery(document).ready(function($){

$(window).unbind('beforeunload');

$("input[type='submit']").click(function(){
     $(window).unbind('beforeunload');
});

$("input").on("change paste keyup", function() {

  $(window).bind('beforeunload', function(){
return 'Are you sure you want to leave?';
  });

});

var contenteditable = document.querySelector('[contenteditable]'),
    text = contenteditable.textContent;



$(contenteditable).each(function(){

$(this).on("change paste keyup", function() {

$(window).bind('beforeunload', function(){
return 'Are you sure you want to leave?';
});

});
});


$("input[type='submit']").click(function(){
     $(window).unbind('beforeunload');
});

});
</script>

In this tutorial, you gonna learn how to give an alert message or alert before leaving page in JavaScript – jQuery.

In the first place, I will like to say that in many cases it is found that users click on a link of a webpage by mistake or close the current tab by mistake. Here, I will show you how to prevent that mistake by adding an alert message or a warning message using JavaScript or jQuery.

Get more detail

with the help of this code you can get warning when  you will exit browser without saving.

Read More Posts

Leave a Reply

Your email address will not be published. Required fields are marked *