Functions are the basic building block of any application, whether they're local functions, imported from another module, or methods on a class. How to prove that the supernatural or paranormal doesn't exist? This JavaScript function is used in different condition like displaying a print page or directing focus ( keeping the crusher blinking ) to user input field as soon as the page is loaded. Theoretically Correct vs Practical Notation. First off, putting scripts at the top and using window.onload is an anti-pattern. I'm not sure what you mean, but I'd suggest looking through. You are trying to call onload rather than assign an event handler. If we want to cancel the transition to another page, we cant do it here. It represents the browser's window. You can read more about it here simple example: export class Example implements OnInit { constructor () {} ngOnInit () { //code that will execute at the start of the loading process } } Share Follow answered Jan 2, 2018 at 8:58 */, // example.com and example.org are not the same origin, // DOMException: Permission denied to access property "origin" on cross-origin object, // This time, the new browsing context has the same origin, Provide alternative ways when JavaScript is disabled, Always identify links leading to a secondary window, WebAIM: Links and Hypertext - Hypertext Links, G200: Opening new windows and tabs from a link only when necessary, G201: Giving users advanced warning when opening a new window. 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. Difference between var and let in JavaScript, Convert a string to an integer in JavaScript. How do you explicitly set a new property on `window` in TypeScript? This event allows you to display a message in a confirmation dialog box to inform the user whether he/she wants to stay or leave the current page. Note: All events named load will not propagate to Window, even with bubbles initialized to true. There exists a special navigator.sendBeacon(url, data) method for such needs, described in the specification https://w3c.github.io/beacon/. Do roots of these polynomials approach the negative of the Euler-Mascheroni constant? It will run the function as soon as the webpage has been loaded. This event is not cancelable and does not bubble. /* global variable that will store the Is a PhD visitor considered as a visiting scholar? How to reset a form using jQuery with .reset() method? window.location.pathname returns the path and filename of the current page. // This is likely caused by built-in popup blockers. In the next example I will show you how to change the code to use TypeScript's Arrow Function. Note: For more details about the target attribute, see or