Use onLoad in Body Tag with Javascript
To use onLoad in the body tag to call a Javascript:
<body onLoad="alert('The page is loading... now!')">
-We enclose Javascript's built-in
event handler onLoad in the body tag.
-We call Javascript's built-in
alert method.
-We enclose our text in single quotes because it's already inside double quotes.
We could also call a script with onLoad:
function coolAl() {
alert("The page is loading... now!");
}
<body onLoad="coolAl()">
-We
created a function and named it
coolAl.
-We
called that function in the onLoad event handler.
Free Copy and Paste Javascript Code:
<script type="text/javascript">
<!--
function coolAl() {
alert("The page is loading... now!");
}
-->
</script>
<body onLoad="coolAl()">
My home page
Resources:
Opening an Alert Box in Javascript
Call your Function in Javascript
Create a Function in Javascript