Is it possible to run JavaScript before any image loads?
Is this default behavior? Dom, script, IMG load?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Javascript runs before images have loaded by default. The
windowobject’sloadevent fires when images have completed loading (for most clients; some versions of Safari have firedloadbefore images complete), but you’re in no way obligated to wait for that event to run code.The jQuery
readyevent (as seen in another comment) fires when the DOM is assumed to be ready for complete interaction (and in some clients, the DOM is progressively ready for interaction as it is parsed). It’s also not necessary, depending on what code you want to run.loadevent (and you’ll want to use an abstraction aroundwindow.addEventListener()andwindow.attachEvent(), rather than assigning towindow.onload.