Im a beginner and i see that line of code a lot on javascript files , for example :
window.onunload=function(){};
when should i use this and what is it role exactly ?
thank you .
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
onunloadis an event that is triggered when the user navigates away from your page, or when the page is “unloaded”.It’s triggered when a user follows a link, or closes the tab. It’s used for clean up. Like saving a user’s data when they leave the page. Usually it’s paired with
onbeforeunload(which is called beforeonunloadis using the same criteria) to warn a user that they have unsaved data.