Skip to main content

Methods Used to Implement Client-side Scripts

Client-side JavaScript code can be embedded within HTML documents in a number of ways:

  • Between a pair of script tags
  • From an external file specified by the src attribute of a script tag
  • In an event handler, specified as the value of an HTML attribute such as onclick or onmouseover
  • In a URL that uses the special javascript: protocol
 
<html>
<head>
<title>Today's Date</title>
<script language="JavaScript">
// Define a function for later use
function print_todays_date( ) {
    var d = new Date( );                  // Get today's date and time
    document.write(d.toLocaleString( ));  // Insert it into the document
}
</script>
</head>
<body>
The date and time are:<br/>
<script language="JavaScript">
  // Now call the function we defined above
  print_todays_date( );
</script>
</html> 
 


Next : Externally Stored Code