how to use window onload function in typescript

Options To handle the load event on images, you use the addEventListener() method of the image elements. then we load it in the already opened secondary window and then you write "In general, however, I'd avoid assigning functions directly to onload in favour of using addEventListener" <-- why? The JavaScript Tutorial website helps you learn JavaScript programming from scratch quickly and effectively. directing focus ( keeping the crusher blinking ) to user input field, Date object & displaying current date and time on button click, getTime() : Date calculations by using milliseconds that is passed from January 1, 1970, Displaying Current Month using getMonth() function, Displaying present Year using getFullYear(), Showing Current Date using getDate() function, Displaying Current Day using getDay() function, Displaying Current Minutes using getMinutes() function, Displaying Current Hours using getHours() function, getUTCHours: Display UTC hour or GMT Hour, getUTCMinutes: Display UTC minutes or GMT minutes, Displaying Current Second using getSeconds() function, gettimezoneoffset() to get difference in UTC time and local time in minutes, setMinutes: Setting the minutes of a date object to fix value, setHours() Setting the minutes of a date object to fix value, setDate() Setting the date part of the date object, setMonth(): Setting the month part of date object, setFullYear(): Setting the year part of the date object, setMinutes(): Setting the minutes part of the date object, toLocaleString() Converting to local date string, toLocaleDateString() Converting to local date string, toTimeString() Converting time part of date object to a string, toUTCString to convert date object to Universal Standard String, Timer function to set time for reminder alert, Recursive timer to trigger a code block after a particular interval, Countdown script displaying days , hours , minutes and seconds left from an event, Displaying changing Clock showing date and time in a web page. Why is this the case? Specifies the width of the content area, including scrollbars. At this point, all of the objects in the document are in the DOM, and all the images and sub-frames have finished loading. To handle the unload event, you can use the addEventListener () method: addEventListener ( 'unload', (event) => { console .log ( 'The page is unloaded' ); }); Code language: JavaScript (javascript) Or assign an event handler to the onunload property of the window object: window .onunload = (event) => { console .log ( 'The page is unloaded' ); }; In general, however, I'd avoid assigning functions directly to onload in favour of using addEventListener (with compatibility libraries if I needed to support older browsers). This event is not cancelable and does not bubble. ,