âš ī¸ Warning âš ī¸ Deprecated Code! This video tutorial contains outdated code.
💡 If you wish to update it, any AI assistant will update the code for you in seconds.

Trap User Check for Unsaved Written Work Tutorial

Published : November 17, 2014   •   Last Edited : November 24, 2025   •   Author : Adam Khoury
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>