Follow these four easy steps and get a clear understanding of the window.onload method. In general you should do the second, but you should attach an event listener to it instead of defining the function. If a law is new but its interpretation is vague, can the courts directly ask the drafters the intent and official interpretation of their law? To quickly begin app development, I use the "Create React . Get code examples like"reload page in typescript". Syntax window.onload = fun() Let's understand this event by using some examples. The following code loads the app.js file after the page has been completely loaded. As DOMContentLoaded waits for scripts, it now waits for styles before them as well. Examples might be simplified to improve reading and learning. To register for the beforeunload event, you use the window.addEventListener () method: window .addEventListener ( 'beforeunload' , (event) => { // do something here }); Code language: JavaScript (javascript) Since the window is the global object, you can omit it like this: addEventListener ( 'beforeunload' , (event) => { // do something here }); Note: All events named load will not propagate to Window, even with bubbles initialized to true. For example: window.addEventListener ('load', function () { alert ('hello!'); }, false); Share Follow Doubling the cube, field extensions and minimal polynoms. Thanks for contributing an answer to Stack Overflow! Function Type Expressions The nature of simulating nature: A Q&A with IBM Quantum researcher Dr. Jamie We've added a "Necessary cookies only" option to the cookie consent popup. Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Fixed A PR has been merged for this issue Help Wanted You can do this Suggestion An idea for TypeScript Milestone TypeScript 2.8.3 A WindowProxy object. For example, if I want to have a pop-up, should I write (directly inside the