Trap User Check for Unsaved Written Work Tutorial
Learn to program a Trap user application like YouTube and Facebook have using JavaScript if the user has unsaved work or has not posted text they have composed yet before they try to leave.
<!DOCTYPE html>
<html>
<head>
<script>
window.onbeforeunload = function(){
var ta = document.getElementById("user_post");
if(ta.value != ""){
return "You have unsaved work!";
}
}
</script>
</head>
<body>
<textarea id="user_post"></textarea>
</body>
</html>