JavaScript

 <  Day Day Up  >  


The most popular client-side scripting language on the Web is JavaScript, a scripting language originally developed by Netscape. Microsoft also supports JavaScript in the form of JScript, a JavaScript clone used in Internet Explorer. The language was turned over to the international standards body European Computer Manufacturers Association (ECMA), which announced during the summer of 1997 the approval of ECMA-262, or ECMAScript, as a cross-platform Internet standard for scripting. Many browser vendors comply with the ECMAScript specification, but users and vendors alike commonly use the widely recognized JavaScript name .

JavaScript will seem very familiar to programmers. The syntax of JavaScript is fairly similar to C or Java with Perl-style regular expression handling. However, unlike Java, the language does not force users to develop in such a style and retains features (such as weak typing) that are common to simple scripting languages. The following is a simple example of JavaScript code that is used to greet the user ; a rendering of the script in action is shown in Figure 14-1.

click to expand
Figure 14-1: JavaScript says hello
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">   <html xmlns="http://www.w3.org/1999/xhtml" lang="en">   <head>   <title>  First JavaScript Example  </title>   <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />   <script type="text/javascript">  <!--     function greet()  {     alert("Hello user! Welcome to JavaScript.");  } //-->  </script>   </head>   <body>   <h1 align="center">  First JavaScript Example  </h1>   <div align="center">   <form action="#">   <input type="button" value="Press Me" onclick="greet()" />   </form>   </div>   </body>   </html>  

This example demonstrates a simple JavaScript function called greet , which is triggered by a user's button press. The event handler attribute onclick is used to tie the markup to the JavaScript that is contained in the head of the document within the script element. Although this example is very simple, remember that it also is a trivial example; this is a real programming language that has many nuances , which are discussed later in this chapter.



 <  Day Day Up  >  


HTML & XHTML
HTML & XHTML: The Complete Reference (Osborne Complete Reference Series)
ISBN: 007222942X
EAN: 2147483647
Year: 2003
Pages: 252
Authors: Thomas Powell

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net