0

hi, how to use the window onload event on javascript.. for example i got a function and i want that function to execute during page load. any ideas is greatly appreciated... thanks...

5
Contributors
5
Replies
9
Views
8 Years
Discussion Span
Last Post by koolhq
0

Here is a sample code:

<html>
<head>
<script type="text/javascript">
function load()
{
//Put your code here
}
</script>
</head>

<body onload="load()">

</body>
</html>
0

The best way to do it:

<html>
<head>
<title>Test Page</title>
<script type="text/javascript">var myFunc = function() {
   alert("Hello World!");
};

window.onload = myFunc;
</script>
</head>
<body>
</body>
</html>
0

You can of course do it with W3 event listeners, IE attatch event, or JQuery as well, but you knew that. :D

0
<html>
<head>
<script type="text/javascript">
var x=0
function displaymessage()
{
while (x==0)
{
x=0
alert("NO!");
}
}
</script>
</head>

<body onload="displaymessage()">
<form>

</form>
</body>
</html>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.