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.
 
ah thanks, although, that wasn't why it was complaining, i had a typo on the end of the line which for some reason was throwing a misleading error
Code:
<body onload="&lt;tmpl_var ID='onload'&gt;"'>
I had an erroneous single quote on the end, d'oh

Now I finally have
This Page Is Valid XHTML 1.1!
woohoo, one other question though, is onContextMenu I.E. specific?

thanks
1DMF

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
No, it isn't. Firefox supports it - not sure what else does though.

The easiest thing to do though (if you are unsure) is to try it.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
is onContextMenu I.E. specific?
As ca8msm says, it works in Firefox. More specifically it has been in Mozilla and Netscape since 2001! Safari supports it.

So whilst it's not a standard, it was introduced as an IE proprietary event that was adopted (like innerHTML) by other browser vendors.

IE 5.2 for the Mac doesn't support it... and it looks like Opera has left it out as well.

I found a lot of information here:


Cheers,
Jeff

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

What is Javascript? FAQ216-6094
 
thanks, w3c won't validate it as an attribute, although the only use i've used it for is to block the menu on right click, which someone called me "Jewish" for doing so.

I'm sure it will be handy on web applications, so you can use it to create your own "Right Click Menu/Options".

I've now taken it out of my pages, for some reason way back when, I thought somehow I was protecting my source code and images, but anyone with half a brain can get to most source code on the web, and I.E. pops up a little menu with a save icon for images now, so it's a pointless task trying to block it.

However I can see future advantages in getting control over what happens when the right mouse click is pressed on a web page.

regards,
1DMF

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
I reckon you have it spot on there... it's ideal for intranet environments where you have a fixed browser on the desktop.

...anyone with half a brain can get to most source code on the web, and I.E. pops up a little menu with a save icon for images now, so it's a pointless task trying to block it...

It's great you have "come around" to this way of thinking... when you suddenly realise that it's not the code that is worth protecting - but the "craft behind the code".

Personally I had this "revelation" after trying to explain to a colleague how I went about building a particular page... they had all the elements (ripped off my site) but didn't have a clue how to put them together in a different way.

I see this happen a lot here... people pick up some scripts and spend ages trying to "glue them" into their pages without understanding how they work.

Anyway, good on you for ditching the code [smile]

Cheers,
Jeff

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

What is Javascript? FAQ216-6094
 
wow - a compliment from the "Code Couch" crew, that's cool!

Like I have said in a previous post, the journey i have ahead of me I know is a long one, but thanks to you guys, I've found the road, so hopefully I'll eventually get to the end!

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
FYI: there is another way to get javascript code to execute after the page has loaded: put the code between script tags using the "defer" attribute:
Code:
<script type="text/javascript" [b][red]defer[/red][/b]>
alert("This will run after the page is loaded.");
</script>
I don't remember whether it runs before or after the onload event handler, but that is easy to test.

Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
thanks for the tip

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
no probs, i'll just tell everyone they have to use I.E.

JOKE!

:p

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
wouldn't that be concidered as a non-wellformed document?

I was under the impression the corrct way is to have a link to an external JS file in the head for all scripts.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
great, that solves one problem i have with a script, i didn't write it and it wants placing just before the body tag.

cheers
1DMF

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
opps typo (END body </body>) tag

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top