Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Closed Thread
onload to preload images (but without a body tag)
Old 09-03-2009, 04:25 PM onload to preload images (but without a body tag)
ericson3000's Avatar
Experienced Talker

Posts: 40
Name: Bob Davis
Location: Los Angeles, CA
Trades: 0
I have a navbar I use that is included on a page using Cold Fusion. So there is are no head or body tags on the navbar.cfm which is called by the main pages of the site.

I would like to preload some rollover images and usually do this by putting an onload in the initial body tag like so:

<body onload onload="MM_preloadImages('_images/common/add-to-cart_hover.gif','_images/common/preorder_hover.gif')">

Can I do this without the <body> tag? Basically like this:

<onload onload="MM_preloadImages('_images/common/add-to-cart_hover.gif','_images/common/preorder_hover.gif')">
ericson3000 is offline
View Public Profile
 
 
Register now for full access!
Old 09-03-2009, 04:54 PM Re: onload to preload images (but without a body tag)
Average Talker

Posts: 17
Name: Jeremy
Location: WV
Trades: 0
no, but you can do this:

<script type="text/javascript">
MM_preloadImages('_images/common/add-to-cart_hover.gif','_images/common/preorder_hover.gif');
</script>
__________________
Adscend Media,
Please login or register to view this content. Registration is FREE

Monetize your content with our content gateway!
Please login or register to view this content. Registration is FREE
AdscendJeremy is offline
View Public Profile Visit AdscendJeremy's homepage!
 
Old 09-03-2009, 05:49 PM Re: onload to preload images (but without a body tag)
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
The body tag is not required to create an onload event, in fact, it is considered bad form by some developers to ever place it directly onto that opening tag. Onload means that the browser will attempt to wait for all images, and all HTML to load before running the script.

If you run the above script at an arbitrary location in the it will run in the order that the document is created. This can have the side effect of slowing things down a bit, since JavaScript is a single threaded language and must execute before deferring to other actions, such as loading the rest of the HTML. Some developers, to avoid this, will place their scripts at the end of the page, right before the closing </body> tag.

You may also defer a script by placing it inside of an onload event without placing it inline onto the opening <body>:
HTML Code:
<script type="text/javascript">
window.onload = MM_preloadImages('_images/common/add-to-cart_hover.gif','_images/common/preorder_hover.gif');
</script>
Note, however, that more than one onload event is not allowed per page; so if you already have one you shouldn't build another one.
__________________
Join me on
Please login or register to view this content. Registration is FREE
wayfarer07 is offline
View Public Profile Visit wayfarer07's homepage!
 
Old 09-03-2009, 06:14 PM Re: onload to preload images (but without a body tag)
ericson3000's Avatar
Experienced Talker

Posts: 40
Name: Bob Davis
Location: Los Angeles, CA
Trades: 0
thanks guys!!!
ericson3000 is offline
View Public Profile
 
Old 09-08-2009, 09:00 PM Re: onload to preload images (but without a body tag)
skywind's Avatar
Skilled Talker

Posts: 74
Trades: 0
you can also use jQuery to implement it, easy to use.

Last edited by chrishirst; 09-09-2009 at 07:30 AM.. Reason: SIG LINK TURNED OFF
skywind is offline
View Public Profile Visit skywind's homepage!
 
Old 09-08-2009, 11:44 PM Re: onload to preload images (but without a body tag)
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
There's no point in using jQuery if it isn't already being used for other things.
__________________
Join me on
Please login or register to view this content. Registration is FREE
wayfarer07 is offline
View Public Profile Visit wayfarer07's homepage!
 
Closed Thread     « Reply to onload to preload images (but without a body tag)
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.90538 seconds with 12 queries