I have an onLoad command in the head and another in the body, but only the second one works. I am assuming the second one cancels out the first. Is there a way around this?
“The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
—Tim Berners-Lee, W3C Director and inventor of the World Wide Web
btw they're not 'commands', but simple variable assignments (to an event handler property) - and the second assignment is simply over-writing the first.
“The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
—Tim Berners-Lee, W3C Director and inventor of the World Wide Web
What's the big deal about putting 2 calls in the body tag? I do it all the time. Or I put them both in the head with the calls: window.onload=function() {'functionName()'};
Nothing, really. But note, my example above is a reoly to a post that has since been deleted.
“The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
—Tim Berners-Lee, W3C Director and inventor of the World Wide Web
is fine if you are scripting for yourself. However, if you plan on sharing the script, this can cause trouble when combined with other script that use body onload.
Having initialization function that is added to <body onload=""> not only avoids such problems, but also gives you freedom to initialize script using other events, which can be used for demo/debugging purposes.
Working web site is not the one that looks the same in a few graphical browsers, but the one that adequately delivers its content to any device accessing it.
Originally posted by Vladdy onload = function()
{ /*Initialize*/
}
is fine if you are scripting for yourself. However, if you plan on sharing the script, this can cause trouble when combined with other script that use body onload.
Having initialization function that is added to <body onload=""> not only avoids such problems, but also gives you freedom to initialize script using other events, which can be used for demo/debugging purposes.
Your point is well taken. It's just that I'm not a big fan of people using scripts without understanding them and I'm rather fond of using:
if (document.getElementById) onload = function () {}
“The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
—Tim Berners-Lee, W3C Director and inventor of the World Wide Web
“The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
—Tim Berners-Lee, W3C Director and inventor of the World Wide Web
I see your reasoning, Charles.
My point is: if a person installing a script, does not understand the basic:
Code:
/* ---- SCRIPT INITIALIZATION ----
* Foo script is initializied using foo.init() method of the foo object
* Foo script uses existing page elements and enhances their functionality,
* therefore it should be initialized after the page has loaded.
* The most common method that satisfies this requirement is adding a
* call to the foo.init() method to the onload attribute value string
* of the document body element:
* <body onload="foo.init()">
*----------------------------------*/
he/she should not be doing it in the first place.
P.S.
I would rather provide information about initialization function and allow competent web masters use it as they see fit (maybe they need to run a few conditional statements before deciding to call it), than hard code initialization and sacrifice flexibility only to "benefit" a few dumb ones.
Working web site is not the one that looks the same in a few graphical browsers, but the one that adequately delivers its content to any device accessing it.
I have had to put calls inside the script tags before to get pages to validate. I was using onresize(), which apparently stops certain doctypes of HTML 4.01 from validating.
I think that you will find that "onresize" is invalid for all types of HTML and XHTML™.
“The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
—Tim Berners-Lee, W3C Director and inventor of the World Wide Web
Bookmarks