Jeff Mcbride Jeff Mcbride - 2 years ago 68
Javascript Question

checking the ace editor in the onbeforeunload to see if changes were made

I'm trying to use the

$(window).on('beforeunload', function(){});
in the ace editor to check if the user made changes to a document but didn't click the submit button but for some reason it doesn't work Here's the code:

editor.on('change', function(Isclean ) {
var Isclean = editor.session.getUndoManager().isClean();
var submitting = false;

$(window).on('beforeunload', function(){
if (submitting == false && Isclean == false) {
return "You have made some changes in the editor.";

But for whatever reason Isclean always returns a boolean of true.

Answer Source

In order to accomplish this task I did:

    $(window).bind("load", function() {

I was pre-loading some Json into the editor so unless i called editor.session.getUndoManager().markClean(); as the last thing to load (and it HAS to be the last thing to load), it would always boolean to false.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download