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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Specify a delay or an order for two scripts to execute

Status
Not open for further replies.

hablablow

Programmer
Sep 9, 2000
115
FR
Hi users,

I am using two scripts in a page
- A script to setup the position of a layer
- A script to preload some images in page

The 2 scripts execute themselves at the same time, making the div i want to position at a very wrong position while images are preloading. When the preload is done, the layer "jumps" to his proper localisation in the page.
This is what i want to avoid.
The first script is called on window.onload.
Is it possible to have a delay ( or an order ) in wich the scripts execute themselves ? 1 second delay in wich the first script would position the layer correctly then start the onload phase...
Thanks in advance for your help
 
Why not use the onload event to call the two functions in sequence?

Code:
onLoad="preload();position();"

Trojan.

 
I believe if you say so but how do i manage to put this as the 2 scripts are in a differenr area in my page ( and don't use onload, only the first does ).
Here is the copy of my two scripts and they should be loaded in this order. Lets say the first needs 1 sec or 2 to position the layer properly, then the loading image process starts.

FIRST SCRIPT ( on top of page )

<script type="text/javascript">
var fixedStuff = null;
var artDiv = null;
var fixedSize = 0;

function checkFixedHeight() {
if ( !fixedStuff ) fixedStuff = document.getElementById ("fixedWrapper");
if ( ! artDiv ) artDiv = document.getElementById("article");
var size = fixedStuff.offsetHeight;
if ( size != fixedSize ) {
fixedSize = size;
artDiv.style.marginTop = fixedSize + "px";
}
setTimeout(checkFixedHeight, 1000);
}

window.onload = checkFixedHeight;
</script>

SECOND SCRIPT ( these are values only the script is in a standalone file )

<script type="text/javascript">
// Time in seconds to wait before giving up on preload (broken
// images can cause the load to never get to 100%).

var bt_timeout = 8;

// Array of images to load; feel free to make this as long or
// as short as you want. First element is filename (include path
// to file), second is size of images in kB.

var bt_preimages = [
['forrest.jpg',1337]
];


// Text to use for when loading has finished
var bt_text_finished = '';

// Text to prefix the percentage
var bt_text_prefix = 'Loaded: ';


function bt_done() {
// stub function called when script is finished, put your JS here.
// (you could use a javascript to redirect the user)
document.getElementById('load').style.display = 'none';
document.getElementById('content').style.display = 'block';

}
</script>

<script type="text/javascript" src="bt_loader.js"></script>

If you could help me telling where and how to insert your onload event

Thanks a lot.
 
I was suggesting using the onLoad event handler in HTML to call the javascript.

Code:
<body onLoad="preload();position();">

I guess you'd have to remove the onload call in your file1 and modify your file2 to be a callable fnuction.

Trojan.

 
ok thanks i see what you mean...
I have then to find a generic name for the two scripts then the order they are mentioned in the onload will be the same order they load into the page, right ?
One last thing: what syntax should i use to wrap this two scripts into a name(); i'll call onload ? Is it

<script type="text/javascript">

preload(); {
Content of all the script 1
}
</script>

Same for script 2 right ?
Then <body onLoad="preload();position();">
Thank you for your help on this TrojanWarBlade.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top