The code below shows how to place javascript in the header of a web page.
Javascript that is placed in the header of a web page between the <head> tags is loaded before the function is called. Javascripts in the header are executed when they are called or when an event is triggered.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Web Development Tutorials.com</title>
<style type="text/css">
</style>
<script type="text/javascript">
function message()
{
alert("This javascript is placed in the header of the web page.");
}
</script>
</head>
<body onload="message()">
</body>
</html>
The code above creates this web page:
how to place javascript in the header of a web page
Use the text editor below to practice what you have learned.