Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 9th, 2003, 11:38 AM
Authorized User
 
Join Date: Jun 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default Body Onload Function Question

I have a JS function that is supposed to be called in the body tag like this:

<body ONLOAD="preloadTopImages();">

Is there a way to call this function without having to put it in the body tag? Can I call it in my JS script in the header tag by making another function that loads this function? Thanks for any help


<script language="Javascript">
<!--
var preloadFlag = false;
function preloadTopImages() {
if (document.images) {
        contract_over = newImage("/test/images/top_nav/contract_vehicl_button_over.gif");
        smallbiz_over = newImage }
}

//-->
</script>
 
Old July 10th, 2003, 02:05 AM
Authorized User
 
Join Date: Jun 2003
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Use the window.onload event. As in:

window.onload = preloadTopImages;

or:

window.onload = function (){
    if (document.images) {
      contract_over = newImage("/test/images/top_nav/contract_vehicl_button_over.gif");
      smallbiz_over = newImage
     }
}


/Robert
 
Old July 10th, 2003, 02:52 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

You can just call it in a script block in the header provided that the function is declared above the call to it and it does not reference any parts of the page which have not yet rendered.

--

Joe





Similar Threads
Thread Thread Starter Forum Replies Last Post
Invoke onClick() function when body onLoad muklee Javascript How-To 2 March 16th, 2007 01:02 AM
onload function calll tannu Ajax 1 November 21st, 2006 01:15 PM
Double DB insert using body.onload needlz BOOK: Professional Ajax ISBN: 978-0-471-77778-6 1 February 20th, 2006 04:18 PM
Problems with Body onload event blaabil Javascript How-To 0 January 6th, 2006 06:45 AM
Response.Write output is of <body></body> yoord BOOK: Beginning ASP.NET 1.0 0 October 13th, 2004 07:06 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.