The function code() is called window.onload. These features include options such as the window's default size and position, whether or not to open a minimal popup window, and so forth. A callback method that is invoked immediately after Angular has completed initialization of a component's view. Scripts that dont block DOMContentLoaded, Scripts that are generated dynamically with, We can send not only a string, but also forms and other formats, as described in the chapter. It sends the data in background. If no parameter type is defined, TypeScript will default to using any, unless additional type information is available as shown in the Default Parameters and Type Alias sections . The notable exception is sending analytics. But it doesnt wait for the image to load. 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' ); }; Theres also the readystatechange event that triggers when the state changes, so we can print all these states like this: The readystatechange event is an alternative mechanics of tracking the document loading state, it appeared long ago. Which "href" value should I use for JavaScript links, "#" or "javascript:void(0)"? An example of data being processed may be a unique identifier stored in a cookie. How to Draw a Half Moon using HTML and CSS? How to see the extensions loaded by PHP ? A WindowProxy object. The window.onload ensures all the elements are loaded and are available for document.getElementById ('my_iframe') to fetch them. Staging Ground Beta 1 Recap, and Reviewers needed for Beta 2. Thanks for contributing an answer to Stack Overflow! You can read more about it here. The only reason people used window.onload is because they mistakenly believed scripts needed to go in the head section. 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? How Intuit democratizes AI development across teams through reusability. If JavaScript support is disabled or non-existent, then the user agent will create a secondary window accordingly or will render the referenced resource according to its handling of the target attribute. Find centralized, trusted content and collaborate around the technologies you use most. Later, when the same image appears in the document (no matter how), it shows up immediately. How do you explicitly set a new property on `window` in TypeScript? That may sound weird, but most browsers ignore event.preventDefault(). // This is likely caused by built-in popup blockers. The example below correctly shows image sizes, because window.onload waits for all images: When a visitor leaves the page, the unload event triggers on window. So you can use defer with addEventListener and it will load fastest in new browsers but still load in old ones. How do I align things in the following tabular environment? Bulk update symbol size units from mm to map units in rule-based symbology. The function that is required to be executed is given here. you write "In general, however, I'd avoid assigning functions directly to onload in favour of using addEventListener" <-- why? window.addEventListener waits for the window to be loaded before running it. If popup is not enabled, and there are no window features declared, the new browsing context will be a tab. This name can be used as the target attribute of or