-2
I have this code that shows a warning as soon as the user changes screen, but I need it to appear only if the user makes any changes to textarea.
What I’ve done so far.
window.addEventListener("beforeunload", function(event) {
event.preventDefault();
event.returnValue = "Deseja sair?";
return "Deseja sair?";
});
How are you doing to check if something has changed? And what kind of things can be changed? Normally it would only be by one
if (alterado) { return "Deseja....or evenif (valororiginal != valoratual) { return "Deseja....inside the Listener, but only you know what characterizes a change in your specific case. It is worth noting that inputs in general has the propertydefaultValue, then do something likeif (element.value != element.defaultValue)is the simplest way and compatible with most scenarios in static HTML.– Bacco