Is the onload event only for <body> tag???

This is a discussion on "Is the onload event only for <body> tag???" within the JavaScript Forum section. This forum, and the thread "Is the onload event only for <body> tag??? are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Jul 24th, 2007, 15:16
Junior Member
Join Date: Feb 2007
Location: USA
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Question Is the onload event only for <body> tag???

I think I already know the answer to this question...No. Unless I'm wrong

Is it possible to associate the onload event with a <div> element?

I'm making an update to an image that is used throughout my site, the site is loaded via a Java Servlet (the image is set as a session attribute), that way if I ever have to change the image, it will be applied site wide, and I won't have to go into each page and make the change manually.

So I just put in a <div> that will pop up when a user hovers over a link, and disappear when they move off it...I don't want the <div> to show when the page loads, and I know the easiest way to accomplish this is to use the onload event of the <body> tag...but that'll mean I have to go into each page of my site and manually make the change to the <body> tag.

Is there a way around this?

Thank You,
-Love2Java
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Jul 24th, 2007, 15:47
Most Reputable Member
Join Date: May 2007
Location: UK
Age: 27
Posts: 1,111
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Is the onload event only for <body> tag???

Quote:
Originally Posted by Love2Java View Post
I'm making an update to an image that is used throughout my site, the site is loaded via a Java Servlet (the image is set as a session attribute), that way if I ever have to change the image, it will be applied site wide, and I won't have to go into each page and make the change manually.
Oh dear. You really do Love2Java, don't you?

You're choosing a complex solution for a simple problem. Use includes instead: such as PHP includes or server side includes (SSI).

Includes allow you to "cut and paste" within your web pages, so that general, reused code can be maintained in a single file. The server does the "cut and paste" job, so the end result has no visible stitches You'll need to set up a local web server for testing offline, but that's actually pretty easy (just grab Apache).

Also, you should be careful to distinguish between javascript and java. Javascript is a lightweight, safe scripting language that enjoys widespread support in browsers; Java is a programming language that does not (for example, I disable Java). They are totally different; the naming is misleading.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Jul 24th, 2007, 17:38
Junior Member
Join Date: Feb 2007
Location: USA
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Is the onload event only for <body> tag???

Yes, Java (Java code, JavaScript, Java Servlets and Java Server Pages) makes up the majority of programming on this site I'm working on...but to clarify, I'm retrieving the image as follows:
Whenever a browser comes to any page on the site, the page checks to see if the session has expired within the page...if it has, a quick, efficient, non complex, call to a servlet goes into the database, retrieves the location of the image, and then sets it as a session attribute to be used across every page on the site.

Its really quite simple and easy to manage. It's not all that complex really.

I'm not looking to get into explaining the complexities and purpose of this site that I'm working on...however, I will say this, the images that I'm retrieving are based on a number, and a call to the database would be necessary at some point anyways.
So the idea to use <include>'s with 1 JSP page containing image locations isn't quite good enough for the task. Sooner or later, like when the session expires, that number will have to be retrieved from the db.
The call to the db to get the image and set the location as a session attribute occurs when a user comes to a page on the site (ex. from a bookmark/favorite), so that's once, and if the session expires sometime after logging in, so that's twice. Not inefficient. But thanks for the suggestion, it was a good one.

Now back to the original purpose of my thread, I don't like to veer off into another subject...and my question has yet to be answered...is it possible to use the onload event via the <div> tag, or is that solely an event handled ONLY by the <body> tag?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Jul 24th, 2007, 20:13
Most Reputable Member
Join Date: May 2007
Location: UK
Age: 27
Posts: 1,111
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Is the onload event only for <body> tag???

Quote:
Originally Posted by Love2Java View Post
...is it possible to use the onload event via the <div> tag, or is that solely an event handled ONLY by the <body> tag?
I don't see why not. Why don't you try it and see?

Having said that, I recommend removing all your event handlers and onload stuff to the .js file itself: http://onlinetools.org/articles/unob.../chapter4.html
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Jul 24th, 2007, 20:51
Most Reputable Member
Join Date: May 2006
Location: North West, UK
Age: 22
Posts: 1,173
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Is the onload event only for <body> tag???

Yes agree with mike. I could give you the lecture but I'll spare you. I will say this though, inline css is frowned upon as inefficient, you should treat JavaScript in the same way. Everything should work perfectly for users without JS enabled for whatever reason. I even go so far as to write (not using document.write) any elements into the page that are only being used by the JS . So if I were creating a JS image gallery and I had a placeholder image which I would change the src of using the setAttribute property then I would dynamically place that element into the html file only if JS was enabled and the script would work. Users with JS enabled would see just a list of thumbnails. The only thing that is required for this image gallery to work (as it is a real one, not a hypothetical one) is a ul with an id of imagegallery. That's it. No extra classes and certainly no inline JS event handlers.

Some people think the methods I have described (poorly) above are over the top but I call those people unprofessional with no car for accessibility and modern standards.

So there. I am no JS expert but what I do, I do correctly. I won't compromise as regards css and html so why should I with JS.

Pete.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Jul 28th, 2007, 19:15
Ryan Fait's Avatar
Elite Veteran
Join Date: May 2006
Location: Las Vegas
Posts: 3,787
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Is the onload event only for <body> tag???

I hate to repeat what the others are saying, but you need to understand you're using the wrong language to accomplish this. PHP, which is very similar to JavaScript in syntax is the ideal language for this task.

To be frank, your suggested method is crude and riddled with holes PHP, as a server side language, won't require you to deal with browser support or extra processes on the clients computer.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old Jul 30th, 2007, 12:38
Junior Member
Join Date: Feb 2007
Location: USA
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Is the onload event only for <body> tag???

Quote:
Originally Posted by Ryan Fait View Post
I hate to repeat what the others are saying, but you need to understand you're using the wrong language to accomplish this. PHP, which is very similar to JavaScript in syntax is the ideal language for this task.

To be frank, your suggested method is crude and riddled with holes PHP, as a server side language, won't require you to deal with browser support or extra processes on the clients computer.
I don't work with PHP, and I don't know any of it for starters. Why is that JavaScript is used on a countless # of web pages then??? This is the first I've heard of anyone suggesting that PHP should be used instead of JavaScript.
Explain, what sort of language is PHP?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old Jul 30th, 2007, 12:44
Most Reputable Member
Join Date: May 2007
Location: UK
Age: 27
Posts: 1,111
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Is the onload event only for <body> tag???

Quote:
Originally Posted by Love2Java View Post
Why is that JavaScript is used on a countless # of web pages then??? This is the first I've heard of anyone suggesting that PHP should be used instead of JavaScript.
Javascript is a client-side language: all the operations happen on the client's computer.

PHP is a server-side language: all the operations happen on the server, before it passes the document on to the client.

Both have their pros and cons. Client-side is great for interacting with the user: choosing personal settings, for example. It's more efficient, because it need not send a request back to the server.

Server-side languages are more powerful, however, because they are not subject to the tight restrictions on running code on a client's computer. They also reduce the processing burden on the client.

It's about choosing the right tool for the job.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
body event, onload event

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
focus() onLoad Jaken Veina JavaScript Forum 1 Apr 22nd, 2006 17:34
Create DIV contents OnLoad from textbox value Davka JavaScript Forum 1 Feb 7th, 2006 20:31
Problem in Setting Cookie on body onload (frame page) call14 JavaScript Forum 1 Dec 20th, 2005 14:47
EVENT: SPARK - Flash Event Flasher Flash & Multimedia Forum 0 Nov 15th, 2005 10:08


All times are GMT. The time now is 14:09.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42