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...

Here is a sample code:

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

<body onload="load()">

</body>
</html>

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>

thanks.. :)

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

<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>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.