By clicking Accept all cookies, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy. Syntax Use the event name in methods like addEventListener (), or set an event handler property. CSS to put icon inside an input element in a form. How to put a responsive clear button inside HTML input text field ? Browser Support Syntax In HTML: <element onload="myScript"> Try it Yourself In JavaScript: Use window.addEventListener: It allows adding event listeners on any HTML document or other objects that support events. What is the correct way to screw wall and ceiling drywalls? Connect and share knowledge within a single location that is structured and easy to search. Post your comments , suggestion , error , requirements etc here, JavaScript Window onload to execute script as soon as page loads and difference between body onload. How Intuit democratizes AI development across teams through reusability. The JavaScript Tutorial website helps you learn JavaScript programming from scratch quickly and effectively. Find centralized, trusted content and collaborate around the technologies you use most. So alert shows zero sizes. Indigo.Design A Unified Platform for Visual Design, UX Prototyping, Code Generation, and App Development App Builder Cloud-based WYSIWYG Drag & Drop Tool, Endless Theming options and Standards-Based Code Output Let me explain my approach. The window object is supported by all browsers. The onload event can also be used to deal with cookies (see "More Examples" below). window.addEventListener waits for the window to be loaded before running it. The following example uses the load event handler to determine if an image, which exists in the DOM tree, has been completely loaded: You can assign an onload event handler directly using the onload attribute of the
element, like this: If you create an image element dynamically, you can assign an onload event handler before setting the src property as follows: The