I have a page where a user can add some data. It' s not a form, but he/she must save it to keep it. I would like to add a function to warn them about not saved items if they click and other link leading to leaving the page.
I've tried this but it does not seem to work:
$(window).on('beforeunload', function(){
if ($('.mustSave').is(':visible').length > 0) {
// alert
}
});
I use jQuery 2.1.1 and I'm afraid some of the code I tried is deprecated.