Click to See Complete Forum and Search --> : Load time
troy1984
10-24-2003, 08:06 PM
Hi all,
I have a javascript on a mouse over button. When i click the button a javascript executes. Standalone the script works fine however when i click my button the site to where my button links loads before the javascript can even begin (a moving layer). My question was if there is some kind of code that says after clicking the button: execute javascript before loading the page the button links to, onclick load page after ---seconds. Anything that can do what i want execute the script before loading the page is fine.
Thanks everyone,
Greetings,
Troy
Khalid Ali
10-24-2003, 08:17 PM
If I understood you correctly, you want to look into
setTimeout('handler',timeDelay)
where handler is any function that you want to be executed and timeDelay is integer value for the time
1000=1 second
troy1984
10-25-2003, 06:52 AM
Tnx Khalid,
I'll look in to that.
Greetings,
Troy
troy1984
10-26-2003, 07:33 AM
I tried to apply it into my script but im affraid my js is to poor... I've searched the internet for setTimeout('handler',timeDelay) and I found (i could be wrong) that the code should look something like this:
<a href="#" onClick="setTimeout('window.OPENSOMETHING',2000)">open</a>
Only i can't figure out how to put it in to my scrip/define it.
This is my script:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<div id="ball" style="position:absolute;"><img src="ball.gif"></div>
<a href="javascript: moveit(400, 100)">About</a> <a href="javascript: moveit(500, 100)">news</a> <a href="javascript: moveit(610, 100)">Sitemap</a> <a href="javascript: moveit(720, 100)">Contact</a>
<br> <a href="javascript: moveit(140, 192)">Why ADF</a>
<script language="JavaScript" type="text/javascript">
step = 1;
startX = 100;
startY = 200;
currentX = startX;
currentY = startY;
function initialize()
{
//Start positions
document.getElementById("ball").style.left = startX;
document.getElementById("ball").style.top = startY;
}
function moveit(x, y)
{
if (currentX < x)
{
document.getElementById("ball").style.left = currentX + step;
currentX = currentX + step;
}
if (currentX > x)
{
document.getElementById("ball").style.left = currentX - step;
currentX = currentX - step;
}
//-----
if (currentY < y)
{
document.getElementById("ball").style.top = currentY + step;
currentY = currentY + step;
}
if (currentY > y)
{
document.getElementById("ball").style.top = currentY - step;
currentY = currentY - step;
}
if ( (currentX != x) || (currentY != y)) setTimeout("moveit("+x+","+y+")",1);
}
initialize();
</script>
</body>
</html>
------------------------------------------------------------------
I want to let the script work like this: When i click on a link. the image move's from point a to point b. (This works thanks to BestZest). Only now i want to put in a delay of 2 seconds ands let him open a real page. So for example: I click on a link the image moves and with the same click it opens a page.
So I click on the link 'About'
This executes the javascript (image slide) and 2 seconds later it opens the page about.html
Thanks again all readers of this form for helping me out.
Greetings Troy
troy1984
10-27-2003, 03:10 PM
The "double links" are not that inportant. But if someone can plz help me out with putting the load time command into the code it would be great. Tnx a lot.
Greetings,
Troy