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.
|
|
|
|
|
![]() |
||
Is the onload event only for <body> tag???
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
#1
|
|||
|
|||
|
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 |
|
|
|
#2
|
|||
|
|||
|
Re: Is the onload event only for <body> tag???
Quote:
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 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. |
|
#3
|
|||
|
|||
|
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? |
|
#4
|
|||
|
|||
|
Re: Is the onload event only for <body> tag???
Quote:
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 |
|
#5
|
|||
|
|||
|
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. |
|
#6
|
||||
|
||||
|
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 |
|
#7
|
|||
|
|||
|
Re: Is the onload event only for <body> tag???
Quote:
Explain, what sort of language is PHP? |
|
#8
|
|||
|
|||
|
Re: Is the onload event only for <body> tag???
Quote:
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. |
![]() |
| Tags |
| body event, onload event |
| Thread Tools | |
|
|
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 |