How to check a dirty flag

I was wondering what the best way is to check if a page is dirty if the user chooses to navigate away from it. For example, there is a registration form and the user enters all their information. Then accidentally clicks on the link to navigate away from it.

I found this on the internet where it checks to see if the page is dirty if a person makes changes to any form input values.

<script type="text/javascript">
var isDirty = false;
var msg = 'You haven\'t saved your changes.';
            isDirty = true;
    window.onbeforeunload = function(){
            return msg;


So this works great. But how can I exclude some of the links that pop up? Is there a better way to do this?


source to share

1 answer

You must add an onclick event listener to these inputs and "return false"; Something like

$('a.className="popup"').onclick = function(){return false};



<a href = "#" onclick = "return false;" > Text </a>



All Articles