<html>
<head>
<title>Javascript page structure</title>
<script language='JavaScript' type='text/JavaScript'>
document.write("Hello World")
</script>
</head>
<body>
This is body content
</body>
</html>
The above code will write Hello World as soon as the page loads to the client browser. We can keep the script inside our body tag also . Like this
<html>
<head>
<title>Javascript page structure</title>
</head>
<body>
This is body content
<script language='JavaScript' type='text/JavaScript'>
alert("Hello World")
</script>
</body>
</html>
Let us change this a bit and use one alert message inside a function. Like this.
<html>
<head>
<title>Javascript page structure</title>
<script language='JavaScript' type='text/JavaScript'>
function start(){
alert("Hello World")
}
</script>
</head>
<body >
This is body content
</body>
</html>
You can see above code will not display the alert message because we have kept the message inside a function and we need to call the function. To call the function onload we have to use the body tag like this.
<body onload=start();>
JavaScript variable
mari | 08-02-2010 |
i need validation for name, email, phone number... |
shushrita | 01-09-2013 |
'text/JavaScript'.This is no longer required. JavaScript is the default scripting language in all modern browsers. |