Skip to content
Fix Code Error

window.onload vs document.onload

March 13, 2021 by Code Error
Posted By: Chris Ballance

Which is more widely supported: window.onload or document.onload?

Solution

When do they fire?

window.onload

  • By default, it is fired when the entire page loads, including its content (images, CSS, scripts, etc.).

In some browsers it now takes over the role of document.onload and fires when the DOM is ready as well.

document.onload

  • It is called when the DOM is ready which can be prior to images and other external content is loaded.

How well are they supported?

window.onload appears to be the most widely supported. In fact, some of the most modern browsers have in a sense replaced document.onload with window.onload.

Browser support issues are most likely the reason why many people are starting to use libraries such as jQuery to handle the checking for the document being ready, like so:

$(document).ready(function() { /* code here */ });
$(function() { /* code here */ });

For the purpose of history. window.onload vs body.onload:

A similar question was asked on codingforums a while
back regarding the usage of window.onload over body.onload. The
result seemed to be that you should use window.onload because it is
good to separate your structure from the action.

Answered By: jmein

Related Articles

  • jQuery Mobile: document ready vs. page events
  • load and execute order of scripts
  • Pure JavaScript equivalent of jQuery's $.ready() -…
  • Trying to append a Polymer element in another…
  • Using aurelia-cli unable to get bootstrap and a…
  • sql query to find priority jobs
  • After a little scroll, the sticky navbar just is not…
  • How do I make it so my bot doesn't send "role given"…
  • How do SO_REUSEADDR and SO_REUSEPORT differ?
  • Load and execution sequence of a web page?
  • What is the purpose of the "role" attribute in HTML?
  • Get the value from select form in EmberJS and ember-data
  • Script Tag - async & defer
  • How to use html template with vue.js
  • org.hibernate.MappingException: Could not determine…
  • Visual Studio debugging/loading very slow
  • Attempt to use Aurelia plugin causing 404 error in browser
  • Error Message : Cannot find or open the PDB file
  • Vue.js, How to get a list of latitude and longitude…
  • Is it possible to apply CSS to half of a character?
  • Polymer trigger function in child element using…
  • How do I include a JavaScript file in another…
  • How to make the overflow CSS property work with…
  • load scripts asynchronously
  • Smart way to truncate long strings
  • Polymer paper-dialog: how can I know when an…
  • Integrating CKEditor with Aurelia
  • Where should I put tags in HTML markup?
  • Difference between Role and GrantedAuthority in…
  • How to get main JQuery Mobile page to display after…
  • What methods of ‘clearfix’ can I use?
  • What does do?
  • Geolocation denied for HTML embedded site - anchor…
  • SQL Server query to find all permissions/access for…
  • Setting equal heights for div's with jQuery
  • The definitive guide to form-based website authentication
  • Vuetify v-tabs v-tab-item overflows window width
  • PHP - Indirect modification of overloaded property
  • getting text input from a form in react.js using Refs
  • Trouble raising an exception using try and except
  • how to apply css on dynamic loaded html content…
  • ERR_TOO_MANY_REDIRECTS for localhost
  • A simple explanation of Naive Bayes Classification
  • List of ANSI color escape sequences
  • Discord.JS, How to use one discord button to allow…
  • What is the JSF resource library for and how should…
  • How to include multiple js files using jQuery…
  • GLYPHICONS - bootstrap icon font hex value
  • How to resize Twitter Bootstrap modal dynamically…
  • What is Ember RunLoop and how does it work?
  • flutter - add network images in a pdf while creating…
  • Issue in passing function in matchDispatchToProps -- React
  • adding to window.onload event?
  • ASP.NET MVC Bundle not rendering script files on…
  • Backbone.js backed list not being refreshed by…
  • Custom event for Foundation 5 top bar dropdown items
  • Vue JS: how bind an checkbox with related select in…
  • Add polymer-dart element to div
  • How can I query a value in SQL Server XML column
  • Can I run javascript before the whole page is loaded?
  • PolymerJS not working on android 4.2.1 and 4.1.2
  • Vue-auth conditionnal redirect after login and role…
  • Polymer paper-dropdown-menu not rendered correctly…
  • How do you cache an image in Javascript
  • Navbar not filling width of page when reduced to mobile view
  • What are the currently supported CSS selectors…
  • Django queryset to string does not return the string…
  • Jquery fadeToggle Trouble
  • Docker compose fails to start a service with an…
  • ExpressJS How to structure an application?
  • Getting a loading scren to work with Polymer
  • RestHeart ACL - User access controls for databases
  • VueJS role based authentication with router
  • Import javascript file after component is mounted
  • NPM vs. Bower vs. Browserify vs. Gulp vs. Grunt vs. Webpack
  • What is your most productive shortcut with Vim?
  • Fields Don't show in django admin
  • How do you parse and process HTML/XML in PHP?
  • Memcached vs. Redis?
  • Why not use tables for layout in HTML?
  • How can I profile C++ code running on Linux?
  • Typeerror: n is undefined in underscore.min.js
  • jQuery events .load(), .ready(), .unload()
  • HQL Responding with…
  • setTimeout function not working : javascript
  • Centering in CSS Grid
  • how can I also check if a member has a specific role…
  • Is JavaScript guaranteed to be single-threaded?
  • Symfony find user by role (JSON array Doctrine property)
  • How to avoid a System.Runtime.InteropServices.COMException?
  • How do I rotate text in css?
  • How to extend and merge a list of objects with…
  • Ukkonen's suffix tree algorithm in plain English
  • Am I paranoid? "Brutally" big Polymer website after…
  • Aurelia: how to manage sessions
  • In CSS Flexbox, why are there no "justify-items" and…
  • How do I return the boolean value from this…
  • How to make script execution wait until jquery is loaded
  • How do i arrange images inside a div?
  • IdentityServer ASP.net CORE MVC ValidAudiences and…

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

Change column type in pandas

Next Post:

How to delete from a text file, all lines that contain a specific string?

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

.net ajax android angular arrays aurelia backbone.js bash c++ css dataframe ember-data ember.js excel git html ios java javascript jquery json laravel linux list mysql next.js node.js pandas php polymer polymer-1.0 python python-3.x r reactjs regex sql sql-server string svelte typescript vue-component vue.js vuejs2 vuetify.js

  • you shouldn’t need to use z-index
  • No column in target database, but getting “The schema update is terminating because data loss might occur”
  • Angular – expected call-signature: ‘changePassword’ to have a typedeftslint(typedef)
  • trying to implement NativeAdFactory imports deprecated method by default in flutter java project
  • What should I use to get an attribute out of my foreign table in Laravel?
© 2022 Fix Code Error