AhmedsJSPart2

AhmedsJSPart2 - 1 2 3 4 5 6 7 8 2.2: Immediate Scripts: In...

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

View Full Document Right Arrow Icon
1
Background image of page 1

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

View Full DocumentRight Arrow Icon
2
Background image of page 2
3
Background image of page 3

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

View Full DocumentRight Arrow Icon
4
Background image of page 4
5
Background image of page 5

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

View Full DocumentRight Arrow Icon
6
Background image of page 6
7
Background image of page 7

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

View Full DocumentRight Arrow Icon
8
Background image of page 8
2.2: Immediate Scripts: In some of our examples, we have placed JavaScript codes in the event attribute’s values. This code will not be executed unless the respective events happen. Initially when the browser displays the page, it goes through every line of your HTML code and resolves the <tags> (that means it displays the contents of the tags). However, it ignores the instructions specified in the event attributes (unless the event happens). 9
Background image of page 9

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

View Full DocumentRight Arrow Icon
In addition to inserting codes in an event attribute, we can simply insert JavaScript code in the <body> of an HTML document (of course within the <script></script> tags). These scripts are often called Immediate Scripts. In commercial Web Pages, the Immediate Scripts may not p lay a great role, but these are extremely useful for learning and to practice JavaScript syntax. Remember, the Immediate Scripts are simply JavaScript codes inside <script> tags in the <body> section. Here is an example: 10
Background image of page 10
11
Background image of page 11

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

View Full DocumentRight Arrow Icon
In the above code, observe that the <script> tag has been included inside the <body> element just like any other HTML tag (such as <p>, <div>, <table> etc.) When the browser loads the document into a Web page, it will simply go in sequence and treat the <script> tag exactly like any other HTML tag. Thus it will execute the JavaScript instruction when it comes to the <script> tag. It will not wait for any event to occur. 12
Background image of page 12
13
Background image of page 13

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

View Full DocumentRight Arrow Icon
14
Background image of page 14
15
Background image of page 15

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

View Full DocumentRight Arrow Icon
16
Background image of page 16
Example of JavaScript alert (We have already discussed the alert). Anyway, we will give an example here again. 17
Background image of page 17

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

View Full DocumentRight Arrow Icon
18
Background image of page 18
alert1.htm 19
Background image of page 19

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

View Full DocumentRight Arrow Icon
20
Background image of page 20
21
Background image of page 21

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

View Full DocumentRight Arrow Icon
2.4: Learning JavaScript Programming Structure Using Immediate Scripts 2.4.1: Introduction: Immediate scripts are JavaScript codes embedded in the <body> section along with other HTML tags. Immediate scripts are great for learning for JavaScript . The <script> tags inside the <body> section are treated by the browser exactly like other HTML tags. On the initial loading of the page, the browser usually goes sequentially to paint the objects on the screen. When it encounters an immediate script, it fires the JS interpreter to execute the instructions until it paints the remainder of the tags. 22
Background image of page 22
2.4.2: The Document Object Model and Scripting Object Hierarchy When a modern browser loads a page, it usually opens a hierarchical set of objects (at the background). These objects are created by the browser automatically following the Document Object Model (DOM ) architecture specifications by W3C. The top level object in the hierarchy is the Window object. The Window object contains many objects. These objects are shown in Figure 1. 23
Background image of page 23

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

View Full DocumentRight Arrow Icon
Figure 1: Hierarchy of Scripting Objects 24
Background image of page 24
In this section, we will focus only on the Document object very briefly. When the browser opens our page, it creates an object named
Background image of page 25

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

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

This note was uploaded on 12/03/2011 for the course INFS 3380 taught by Professor Ahmed during the Fall '11 term at Toledo.

Page1 / 105

AhmedsJSPart2 - 1 2 3 4 5 6 7 8 2.2: Immediate Scripts: In...

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

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