The event used is called onbeforeunload .
<html> <head> <script type="text/javascript" src="jquery.js"></script> </head> <body> <input id="foo"></input> <script type="text/javascript"> function unloadMessage() { return "Are you sure you want to leave?"; } function setConfirmUnload(enabled) { window.onbeforeunload = enabled ? unloadMessage : null; } $(document).ready(function() { $("#foo").keypress(function() { setConfirmUnload(true); }); }); </script> </body> </html>
William brendel
source share