prompt on exit

code to alert user on closing the window if save was not performed.

by Oliver Kelso

HTML

<button id="save" value="Save">Save</button>

JavaScript

var hasUnsaved = true;

$("#save").on('mousedown', function(){
    hasUnsaved = false;
    alert("You have been saved!");
});

$(window).bind('beforeunload', function(){
    if(hasUnsaved == true){
        return 'WATCH OUT!! \n Your work has not been saved yet.';
    }
});