Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

xhtml <body onload> attribute 7

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
GB
is this right? XHTML doesn't allow "onload" for the body tag.

how do you fire up javascript when the page has loaded without it?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Don't forget to declare scripts as CDATA for XHTML well-formedness:
Code:
<script>
  [COLOR=green]// <![CDATA[[/color]
    [i]foo[/i]
  [COLOR=green]// ]]>[/color]
</script>
This prevents characters like < and > being misinterpreted as the start of a tag (e.g. [tt]if(x<y)[/tt]).

---
Marcus
better questions get better answers - faq581-3339
accessible web design - zioncore.com
 
wow i didn't know that, thanks, I take it i don't need that if the HTML links to external JS files? only around embedded scripts

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
1DMF said:
I take it i don't need that if the HTML links to external JS files? only around embedded scripts

Quite right.

In fact, you only need it if your script contains characters which create malformed XML (such as angle brackets <>). I also use templating engines, so I make the template system mark all embedded scripts as CDATA, just to be sure.

---
Marcus
better questions get better answers - faq581-3339
accessible web design - zioncore.com
 
manarth said:
Don't forget to declare scripts as CDATA for XHTML well-formedness:

Do you know - I've never actually read up on what CDATA did! Thanks for pointing it out - I'll remember that one now.

I always lilke it when I learn new things - it makes you appreciate how helping other people out is a good thing.

Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
According to MSDN, the defer attribute is compliant with HTML 4.0 and W3C DOM Level 1. If it has no effect in Firefox, then there is a problem with Firefox.

Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
w3c said:
defer [CI] - When set, this boolean attribute provides a hint to the user agent that the script is not going to generate any document content (e.g., no "document.write" in javascript) and thus, the user agent can continu
A hint. It does not state that the user agent needs to take specific action. I don't see a problem here with Firefox.

Cheers,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top