0

When you edit a builtin field in Wordpress like the title and don't save the cahnges, and attempt to go to another link, a warning alert box comes up stating that "changes may be lost if you navigate ...".

How can I make that same box appear for my own pages?

Thanks!

2

you have to make a javascript code similar to this...

jQuery(function ($) {

    name = $('#name').val();
    $('#name').data('old_value',name);

    window.onbeforeunload = function () {
        if ($('#name').data('old_value') !== $('#name').val())
            return 'You have unsaved changes!';
    }

});

here's a demo page... try closing the page after changing the value of the textbox there...

  • 1
    Wow I didn't think it'll be that simple lol! – Yahya Uddin Feb 1 '15 at 3:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.