HTML and CSS Reference
In-Depth Information
Figure 10-7
comparing java and javascript
A compiled language
An interpreted language
Requires the JDK (Java Development Kit) to
create an applet
Requires a text editor
Requires a Java virtual machine or interpreter
to run an applet
Requires a browser that can interpret JavaScript code
Applet files are distinct from HTML files
Programs can be embedded within HTML files
Source code is hidden from users
Source code is accessible to users
Powerful, requiring programming knowledge
and experience
Simpler, requiring less programming knowledge and
Secure; programs cannot write content to a
hard disk
Secure; programs cannot write content to a hard disk;
however, there are more security holes than in Java
Compiled code runs on the client side com-
puter within an applet window
Code run on the client side computer directly within
the Web browser
Through the years, JavaScript has undergone several revisions. Included with the
introduction of HTML5 are several new JavaScript components and features that are not
supported in older browsers. Because of this, you need to test your JavaScript code on a
variety of browsers and platforms in the same way you test your HTML and CSS code.
Working with the script Element
A JavaScript program can be placed directly in an HTML file or it can be saved in an
external text file. Placing JavaScript code in a Web page file means that users need to
retrieve only one file from the server. In addition, because the code and the page it
affects are both within the same file, it can be easier to locate and fix programming
errors. However, if you place the code in a separate file, the programs you write can
be shared by the different pages on your Web site in the same way that an external
style sheet can be shared among several Web pages. In this tutorial, you'll work with
JavaScript code entered into an HTML file as well as code stored in an external file.
You'll first examine how to insert JavaScript code directly into an HTML file.
Creating a script element
Scripts can be embedded anywhere within an HTML file using the script element
<scriptƒtype=” mime-type ”>
ƒƒƒ scriptƒcommands
where mime-type defines the language in which the script is written and scriptƒcommands
represents commands written in the scripting language. The type attribute is required for
XHTML documents and should be used for HTML5 documents as well. The MIME type for
JavaScript programs is text/javascript , meaning that to embed a JavaScript program, you
would use the following form:
ƒƒƒ JavaScriptƒcommands
Search WWH ::

Custom Search