PPT13_JavaScript - JavaScript JavaScript JavaScript and...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
JavaScript JavaScript JavaScript and Java are two entirely different programming languages. Netscape and Sun developed the JavaScript language for generating interactive and dynamic Web pages. JavaScript, sometimes referred to as JS, works well for developing Web pages but cannot be used for stand-alone applications. JavaScript Can be embedded in an HTML document. It provides the use of control structures. It provides components such as buttons, and provides for event handling It can interact with an Applet Writing a Script A script file can be read as a separate file or embedded in an HTML file. To place the script in an HTML file, enclose the script in script tags. The tags are not case-sensitive. <Script language = JavaScript> script goes here </Script> A problem can occur if a user attempts to display the HTML page in a browser that does not support JavaScript. Although Netscape 2 and Internet Explorer 3 support JavaScript, some features don't work correctly on these early versions. JavaScript runs best on at least version 4 of both Netscape and IE. You can solve the compatibility problem by hiding the script when necessary. You just include tags that turn the script into HTML comments, and a browser that doesn't recognize the script ignores those lines. Writing a Script Continued The tag "<!--" begins the hiding and "-->" terminates it. <Script language = JavaScript> <!-- Hide JavaScript script goes here // Terminate JavaScript hiding --> </Script> You should include the JavaScript version number in the code. Comments You can create comments in HTML code using opening and closing tags. Inside a JavaScript you write comments by using the Java comment symbols for single-line or multi-line comments. The document.write Method Each Web page is considered a document object. An easy way to display information on a Web page is to use the Document's write method. Enclose the information to display in quotes. document.write(“Hello World”); In JavaScript you can use either single or double quotes, such as "Hello World" or 'Hello World'. However, you must be consistent within the same literal. But be aware that JavaScript statements are case-sensitive, it's only the HTML tags that are not. More Tags You can include HTML tags inside JavaScript code. For example, to make a literal appear in bold font, use the HTML <b> </b> tags inside the literal.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 4

PPT13_JavaScript - JavaScript JavaScript JavaScript and...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online