Onload and load

A

amit

Hello,

the javascript I'm using is not embedded into HTML but included. When I
looking at w3schools.com it uses examples with js embedded into html.

Anyway, when I use:

function load()
{
....
}

The page gets loaded into Firefox and then it executes all statements
inside the function but in IE the function will be totally ignored!
even onload() is ignored.

How should I implement the OnLoad() event in test.js file included in
test.html?

Thanks!
Amit.
 
R

Randy Webb

amit said the following on 7/27/2006 8:38 PM:
Hello,

the javascript I'm using is not embedded into HTML but included. When I
looking at w3schools.com it uses examples with js embedded into html.

Anyway, when I use:

function load()
{
....
}

The page gets loaded into Firefox and then it executes all statements
inside the function but in IE the function will be totally ignored!
even onload() is ignored.

How should I implement the OnLoad() event in test.js file included in
test.html?

The same way you would if you included it in the HTML:

window.onload=someFunction;
 
A

amit

Randy said:
amit said the following on 7/27/2006 8:38 PM:

The same way you would if you included it in the HTML:

window.onload=someFunction;


Hi Randy

I'm confused! in html we could have:

<html>
<head>
<script type="javascript">
function load()
{
alert("page is loaded ...");
}
</script>

</head>
<body onload="load()">
</body>
</html>

right? now where I should put the "onload="load()" in my code? where
should I call the function?


Thanks.
Amit
 
R

Randy Webb

amit said the following on 7/28/2006 1:29 AM:
Hi Randy

I'm confused! in html we could have:

That is becoming obvious :)

Did you test the above code?
<html>
<head>
<script type="javascript">
function load()
{
alert("page is loaded ...");
}

Right here:

window.onload = load;

</script>

</head>
<body onload="load()">

Remove the onload attribute from the body tag.
right? now where I should put the "onload="load()" in my code? where
should I call the function?

You don't put onload="load()" in your external file, you give
window.onload a reference to the function you want to execute, and,
don't use the () on the window.onload statement.

window.onload = someFunctionToRunWhenTheWindowIsLoaded;
 
A

amit

Randy said:
amit said the following on 7/28/2006 1:29 AM:

That is becoming obvious :)

Did you test the above code?


Right here:

window.onload = load;



Remove the onload attribute from the body tag.


You don't put onload="load()" in your external file, you give
window.onload a reference to the function you want to execute, and,
don't use the () on the window.onload statement.

window.onload = someFunctionToRunWhenTheWindowIsLoaded;





I followed your steps but nothing works! I haven't got rest since
yesterday maybe later but thanks.
 
A

amit

amit said:
I followed your steps but nothing works! I haven't got rest since
yesterday maybe later but thanks.


Ok, now it is working. last night I was too tired!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,112
Latest member
VinayKumar Nevatia
Top