Javascript onload in HTML

html, javascript, jsp

Solution

Onload can only be used for `<body>`, `<img>`, `<script>`, `<iframe>` tags, because it tells you when an external resource (image, script, frame) or the whole page (body) has been loaded

Since HTML5 these can also fire a load event: `<link>`, `<style>`, `<input type=image>`, `<object>` Support for these can still be a hit or miss though (e.g. older Android browsers)

Problem

I want to ask a question about the Javascript’s `onload`. I’m writing a JSP page with the code `<%@ include file ="body.jsp"`. The included `body.jsp` contains: ``` <table onload="function()"> ``` This should load the javascript function, but it doesn't appear to have any effect on the page. Is `onload` only usable on the `body` tag?

Original source