Top Questions

  • 2.9 Years

    • Category : Jquery
    • Location : Chandigarh
    • Posted On : Dec 29, 2016

    you can prevent your page if some changes has been done on page.and show warning to user if they won't to leave page

    function enableBeforeUnload() {
        window.onbeforeunload = function (e) {
            return "Discard changes?";
        };
    }
    function disableBeforeUnload() {
        window.onbeforeunload = null;
    }
    $('input, textarea, select').change(function(event){
      enableBeforeUnload();
    });
    /***Using Jquery**/
    $('#formid').submit(function(){
     disableBeforeUnload();
    });
    /***useing html**/
    <form action="" onsubmit="disableBeforeUnload();" method="post>
    //your code
    </form>

Add Your Answer

When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
Let's work to help developers, not make them feel stupid.