CharlesHarrison Posted June 25, 2009 Share Posted June 25, 2009 According to W3Schools documentation ... W3Schools onload Event... the <script> tag is supposed to support the onload event, and indeed inserting one works, but the tag won't validate at W3Schools, why is this? Note: The page tested has a Transitional doc type. Link to comment Share on other sites More sharing options...
jlhaslip Posted June 25, 2009 Share Posted June 25, 2009 Place the js into an external file. Link to comment Share on other sites More sharing options...
Ingolme Posted June 26, 2009 Share Posted June 26, 2009 I don't see why you need an onload attribute on the script tag anyways. You could just put whatever code you want at the end of the script and it should work. <script type="text/javascript" onload="alert(1)">function X() { // Some code}</script> is the same as <script type="text/javascript">function X() { // Some code}alert(1);</script> Link to comment Share on other sites More sharing options...
CharlesHarrison Posted June 26, 2009 Author Share Posted June 26, 2009 I don't see why you need an onload attribute on the script tag anyways. You could just put whatever code you want at the end of the script and it should work.But if the js is pulled in asynchronously from a third party one might need to know when it has finished loading. Also, the problem is not how to do it, I've already got an example to work.I want to know which is correct, W3Schools or the online validating tool. Is it valid Transitional to include an onload attribute to a script tag, or not? Link to comment Share on other sites More sharing options...
Ingolme Posted June 26, 2009 Share Posted June 26, 2009 The W3C specification says that the onload attribute can only be used on the <body> and <frameset> elements.I'm surprised, as I was quite sure the <img> element also supported it. Link to comment Share on other sites More sharing options...
CharlesHarrison Posted June 26, 2009 Author Share Posted June 26, 2009 The W3C specification says that the onload attribute can only be used on the <body> and <frameset> elements.I'm surprised, as I was quite sure the <img> element also supported it.Thanks. That explains why the validator is rejecting it then. Perhaps W3Schools should update their documentation? Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.