So that being said...Lets get to it.
Tip 1: Onload Event (JavaScript)
Below are a few ways to call an onload event.
This is how to call the onload in the <body>.
****Start Example Code****
<!DOCTYPE html>
<html>
<title>Tip 1: onload Event (JavaScript) demo 1</title>
<script>
//this is the function to be ran onload
function FirstFunction() {
alert("This will be ran first.");
}
</script>
<body onload="FirstFunction()">
<p>Tip 1: onload Event (JavaScript) demo 1</p>
</body>
</html>
****End Example Code****
<!DOCTYPE html>
<html>
<title>Tip 1: onload Event (JavaScript) demo 1</title>
<script>
//this is the function to be ran onload
function FirstFunction() {
alert("This will be ran first.");
}
</script>
<body onload="FirstFunction()">
<p>Tip 1: onload Event (JavaScript) demo 1</p>
</body>
</html>
****End Example Code****
This is how to call just with script outside of the <body>.
****Start Example Code****
<!DOCTYPE html>
<html>
<title>Tip 1: onload Event (JavaScript) demo 2</title>
<script>
//this is the function to be ran onload
function FirstFunction() {
alert("This will be ran first.");
}
window.onload=FirstFunction;
</script>
<body>
<p>Tip 1: onload Event (JavaScript) demo 2</p>
</body>
</html>
****Start Example Code****
<!DOCTYPE html>
<html>
<title>Tip 1: onload Event (JavaScript) demo 2</title>
<script>
//this is the function to be ran onload
function FirstFunction() {
alert("This will be ran first.");
}
window.onload=FirstFunction;
</script>
<body>
<p>Tip 1: onload Event (JavaScript) demo 2</p>
</body>
</html>
****Start Example Code****
If you like this post and want to see more, follow me on my website www.chadcompton.com
Or if you prefer...
No comments:
Post a Comment
Drop me a line.