Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction into JavaScript Java 1 JavaScript JavaScript programs run from within an HTML document The statements that make up a program in an HTML.

Similar presentations


Presentation on theme: "Introduction into JavaScript Java 1 JavaScript JavaScript programs run from within an HTML document The statements that make up a program in an HTML."— Presentation transcript:

1

2 Introduction into JavaScript Java 1

3 JavaScript JavaScript programs run from within an HTML document The statements that make up a program in an HTML document are contained between the … tag pairs The LANGUAGE attribute of the tag tells the browser which scripting language and which version of the scripting language is being used …

4 JavaScript If the browser does not support the JavaScript version, it ignores all statements between the tags To tell the Web browser the statements that follow need to be interpreted by the JavaScript scripting engine, you need the following code JavaScript statements;

5 JavaScript In addition to being an interpreted scripting language, JavaScript is an object-oriented programming language An object is programming code and data that can be treated as an individual unit or component Individual lines in a programming language are called statements Groups of related statements associated with an object are called methods The most common object is the Document object

6 Document Object The Document object represents the content of a browser’s window Any text, graphics, or other info displayed in a Web page is part of the Document object The most common use of a Document object is to add text to a Web page You can create text with the write(…) method or the writeln(…) method of the Document object

7 Document Object The object is connected to the method with a period document.writeln(…) The parentheses contain any required arguments or parameters An argument is any text of info that can be passed to a method The write and writeln methods of a Document object require a text string as an argument A text string (literal string) is text that is contained within double quotes

8 Methods The write and writeln methods of adding text is similar to when you manually add text using standard HTML The only difference between the write and writeln methods is that the writeln adds a carriage return after the line of text The carriage return is only recognized if the text is inside a tag which stands for preformatted text tag tells the browser that any text and line breaks contained between the tags are to be rendered exactly as they appear

9 Creating a JavaScript Source File JavaScript usually incorporated directly into an HTML document, but can be brought in as an external file This external file is called a Source File and have a file extension.js A.js file only contains JavaScript and does not contain HTML tags or the tags HTML doc. contains the tags and a SRC attribute to locate the JavaScript When using a SRC, the browser will ignore any other JavaScript located between the tags

10 Adding Comments JavaScript supports two types of comments – Line comments – Block comments Line comments are created by adding two slashes // before the comment line Block comments span multiple lines and are created by adding /* before the first line and */ after the last line

11 Hiding JavaScript for Incompatible Browsers If a browser is not compatible with the author JavaScript, it will display all the code as if it were text Creating JavaScript source files hides the code from incompatible browsers If HTML comment code is place inside the tags, but before any objects, the code will no longer show tags are placed after the tags and display a message if the browser does not support the JavaScript

12 Placing JavaScript in the Head or Body Sections A browser renders tags in the order in which they appear So the info in the head is rendered before the body text By placing JavaScript in the head, your code that performs behind the scenes tasks will be present when it is required by the code that is located in the body

13 JavaScript document.writeln("Hello World Wide Web") //this is a comment line This will show if browser does not support JavaScript

14 JavaScript 1 Assignment Create a JavaScript web page contains: – “Hello World Wide Web” – Five or six complete sentences that say what you did this weekend and how it went – Text must be in a JavaScript Source File (.js) – Preformatted Text Tags – Incompatible Browser information – One comment line


Download ppt "Introduction into JavaScript Java 1 JavaScript JavaScript programs run from within an HTML document The statements that make up a program in an HTML."

Similar presentations


Ads by Google