1. Trang chủ
  2. » Công Nghệ Thông Tin

Web technologies and e-services: Lecture 5 - Dr. Thanh Chung Dao

41 3 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Web Technologies and E-Services: Lecture 5 - Dr. Thanh Chung Dao
Người hướng dẫn Dr. Thanh-Chung Dao
Trường học Hanoi University of Science and Technology
Chuyên ngành Web Technologies and E-Services
Thể loại Lecture
Năm xuất bản 2020-2
Thành phố Hanoi
Định dạng
Số trang 41
Dung lượng 2,15 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Web technologies and e-services: Lecture 5 provide students with knowledge about: Document Object Model (DOM); introduction of DOM; overview of DOM; DOM examples; how the DOM really works; advantages and disadvantages; DOM or SAX;... Please refer to the content of document.

Trang 1

Instructor: Dr Thanh-Chung Dao Slides by Dr Binh Minh Nguyen

Department of Information Systems School of Information and Communication Technology Hanoi University of Science and Technology

Document Object Model (DOM)

§ How the DOM Really works?

§ Advantages and Disadvantages

§ DOM or SAX

§ Summary

Trang 2

§ JAVASCRIPT - How to make Web Content Dynamic.

3

3

World Wide Web Consortium-W3C

Trang 3

§ W3C is a vendor Organization.

§ Main Vendors are Netscape and Microsoft

§ Some W3C Standards are HTTP,HTML,XML,CSS

§ DOM is also Recommend by W3C

5

5

Overview

The Document Object Model ( DOM ) is an API that allows programs

to interact with HTML (or XML) documents

§ In typical browsers, the JavaScript version of the API is provided

§ W3C recommendations define standard DOM

Trang 4

HTML XML JAVA

SCRIPT

ANY LANGUAGE

7

7

W3C

Trang 5

the Web functions are working properly

§ In this layer the work is mostly complete But some

minor changes is occur

Partial Output

Proposed

Trang 6

Recommendation:-Working Not Working

MICROSOFT IE

11

11

Working With

W3C MEMBERS

Working Drafts

Trang 7

Status Of The DOM

Trang 8

3)Events

4)Style

5)Traversal and Range

6)and the DOM2 HTML

15 15

15

W3C candidate recommendation, 7 Nov 2003

It contains five different specifications:

1)DOM3 Core

DOM Level 3:

Trang 9

Overview of DOM

17

17

DOM Introduction

Example: “Rollover” effect

Cursor not over image Image changes when cursor

moves over

Trang 10

19 19

DOM Introduction

Import JavaScript code

Trang 12

Notice that id of image is first argument to show()

23

DOM Introduction

Trang 15

Image src changed to CFP22.png when mouse

is over image, CFP2.png when leaves

29

Document Tree

Recall that HTML document elements form a tree structure, e.g.,

DOM allows scripts to access and modify the document tree

Trang 16

31

Referencing Objects-Each Object is

Identified by Object Name.

Trang 17

Object Names

n General form is

TO Access The History

To Access The Body

The DOM structure model

o It is a Hierarchy of Node objects

n node object

Element Attribute

etc

Trang 18

Document Tree: Node

String produced by TreeOutline():

Trang 19

</message>

Node is created for message element:

– message element has child element: body.

– body element has Text “Hello!"

– Attributes: from and to also are nodes in DOM tree.

37

The DOM Interface

o The DOM has many interfaces to handle

various node objects

o Every interface has its “Attributes” and

“Methods”

n Compare with Object Oriented Programming

(OOP).

Method Method

Property Attribute

Object Class Interface

OOP DOM

Trang 20

</h t m l >

# t e x t

H 1

H 2 P

Trang 22

getNodeName Returns the node’s name

getNodeType Returns the node’s type (e.g., element, attribute,

text, etc.)

getNodeValue Returns the node’s value

getParentNode Returns the node’s parent

hasChildNodes Returns true if the node has child nodes

removeChild Removes a child node from the node

replaceChild Replaces a child node with another node

setNodeValue Sets the node’s value

insertBefore Appends a child node in front of a child node

43

43

document

.firstChild childNodes[0]

Trang 23

.getElementById()

.getElementByTag()

returns a specific element

.nodeValue

='bold bit of text';

Trang 24

47 https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_doc_body

47

NAVIGATOR

Trang 27

53

53

Trang 30

59

DOM’s other examples

https://www.w3schools.com/jsref/dom_obj_all.asp

Trang 31

Event instance properties:

§ type: name of event (click, mouseover, etc.)

§ target: Node corresponding to document element that generated the event (e.g.,

button element for click, img for mouseover) This is the event target

61 61

DOM Event Handling

JavaScript event listener : function that is called with Event instance when a

certain event occurs

An event listener is associated with a target element by calling

addEventListener() on the element

Trang 32

63 63

DOM Event Handling

Event

target

Trang 33

Event type

65

DOM Event Handling

DOM event types:

§ All HTML intrinsic events except keypress, keydown, keyup, and dblclick

§ Also has some others that are typically targeted at the window object:

Trang 35

Normally false (more later)

69

DOM Event Handling

Trang 36

71

How the DOM Really works?

Trang 37

document

Web Client side program (e.g.: JavaScript)

Web Server side program (e.g.: ASP)

Console program (e.g.: C++, Java)

Output DOM

Trang 38

DOM Advantages & Disadvantages

75

75

DOM Advantages & Disadvantages

ADVANTAGES

- Robust API for the DOM tree

- Relatively simple to modify the data structure

and extract data

Trang 39

Konqueror Opera Camino Safari

77

77

SUMMARY

Trang 40

and extract data from an XML document

o JAXP provides a vendor –neutral interface

to the underlying DOM or SAX Parser

Trang 41

email: chungdt@soict.hust.edu.vn

81

Ngày đăng: 29/10/2022, 06:44