Forum Moderators: open

Message Too Old, No Replies

On Load

         

Adam5000

3:03 pm on Apr 13, 2005 (gmt 0)

10+ Year Member



Great group with great people in it.

I've got a problem with the on load event keyword. It doesn't seem to want to work for me. What I'm trying to do is load an image and then after the image is fully loaded, write the word "Greetings"

But I can't get it to work with the on load keyword and I've got two examples below. The first one calls the function w() (which writes the word "Greetings") outside the body tag, and it works.

In the second one, I try to call the function w() inside the body tag with the on load keyword but for some reason it dosen't work.

Would someone show me where I'm off? I'm using MSIE version 6 if that makes a difference.

Help!

This one works.

<html>
<head><font face=times new roman size=6>
<title>Greetings</title>

<img src="Image 1.jpg" width=150 height=175>

<script language="Javascript">

function w()
{window.document.write("Greetings");}

w()

</script>

</head>

<body>

</font>
</body>
</html>

But for some reason, this one doesn't.

<html>
<head><font face=times new roman size=6>
<title>Greetings</title>

<img src="Image 1.jpg" width=150 height=175>

<script language="Javascript">

function w()
{window.document.write("Greetings");}

</script>

</head>

<body onLoad="w();">

</font>
</body>
</html>

cmatcme

3:19 pm on Apr 13, 2005 (gmt 0)

10+ Year Member




Try

 <body onLoad="w()"> 

Works for me

cmatcme

Great group with great people in it. Seen that before somewhere ;)

[edited by: cmatcme at 3:31 pm (utc) on April 13, 2005]

Bernard Marx

3:22 pm on Apr 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If doc.write is used after the HTML has finished loading, it will overwrite the document.

dcrombie

3:24 pm on Apr 13, 2005 (gmt 0)



You can't "document.write" to a page after it's loaded.

Edit: Snap!

Adam5000

4:47 am on Apr 19, 2005 (gmt 0)

10+ Year Member



Thank you all for your help. This is a great group of people and I'm glad to find others with interests similar to mine.

Going down the, you can't write to a page that's already been written path, I changed the document.write("Greetings") to alert("Greetings") and it worked fine. So I think that was the trouble.

The home page has animation on it (Images moving across the screen) and the problem was, the images needed to be fully loaded before they started to move. If not, then the images would be loading as they moved across the screen.

It was so neat. All I had to do was use onLoad to call the function that starts the animation. It was like starting a whole series of events by pushing one button. I thought that was so cool.

Thanks again for your help. It's a great group and it's good to find people whose intersts are similar to my own. Although I may have to put covers over your heads so the sun can go down.