Web Page Programming with HTML,DHTML & JavaScript/Session 9/ 3 of 21 Event Object - Concept Events are a result of an action done by the user An event may be user-generated or genera
Trang 1The Browser Objects in JavaScript
Session 9
Trang 2Web Page Programming with HTML,DHTML &
JavaScript/Session 9/ 2 of 21
Objectives
Trang 3Web Page Programming with HTML,DHTML &
JavaScript/Session 9/ 3 of 21
Event Object - Concept
Events are a result of an action done by the user
An event may be user-generated or generated by the system
Each event has an associated event object The event object provides information on:
the type of event
the location of the cursor at the time of the event
The event object is used as a part of an event handler
Trang 4Web Page Programming with HTML,DHTML &
JavaScript/Session 9/ 4 of 21
Event – Life Cycle
returns
Trang 5Web Page Programming with HTML,DHTML &
Trang 6Web Page Programming with HTML,DHTML &
JavaScript/Session 9/ 6 of 21
Handling the Events
This segment of JavaScript code that will be executed in response to the event is called an event handler
<INPUT TYPE="button"
NAME="docode"
onClick="DoOnClick();">
Event Handler are categorized as:
Event handlers for HTML tags
<TAG eventHandler="JavaScript Code">
Event Handlers as Properties
object.eventhandler = function;
Trang 7Web Page Programming with HTML,DHTML &
JavaScript/Session 9/ 7 of 21
onClick - Example
The onClick event is generated whenever the user clicks the mouse button on certain form elements or on a hypertext link
Trang 8Web Page Programming with HTML,DHTML &
JavaScript/Session 9/ 8 of 21
onClick - Output
Trang 9Web Page Programming with HTML,DHTML &
JavaScript/Session 9/ 9 of 21
onChange - Example
The onChange event occurs whenever a form element changes This can happen whenever the contents of a text control changes, or when a selection in a selection list changes
} // end hiding from old browsers >
</SCRIPT>
</HEAD>
<BODY bgColor = white>
<FORM>
Please enter a number:
<INPUT type = text size = 5 onChange="checkNum(this.value)">
</FORM>
</BODY>
</HTML>
Trang 10Web Page Programming with HTML,DHTML &
JavaScript/Session 9/ 10 of 21
onChange - Output
Trang 11Web Page Programming with HTML,DHTML &
The onMouseOut event is generated whenever the mouse cursor
moves off of an element
Trang 12Web Page Programming with HTML,DHTML &
Trang 13Web Page Programming with HTML,DHTML &
JavaScript/Session 9/ 13 of 21
onMouseOut -Output
On moving the mouse over Aptech, the following output
is displayed
Trang 14Web Page Programming with HTML,DHTML &
JavaScript/Session 9/ 14 of 21
onLoad - onSubmit onMouseDown - onMouseUp
Trang 15Web Page Programming with HTML,DHTML &
JavaScript/Session 9/ 15 of 21
onResize - Example
This event is activated when a resize event occurs That is,
when a user or script resizes a window or frame
Trang 16Web Page Programming with HTML,DHTML &
Trang 17Web Page Programming with HTML,DHTML &
An object can be defined as a single entity, consisting of
Properties and Methods
A property is a value that belongs to an object
Eg: Document.bgcolor
Trang 18Web Page Programming with HTML,DHTML &
Trang 19Web Page Programming with HTML,DHTML &
JavaScript/Session 9/ 19 of 21
Window Object
Attribute Value Description (IE)
toolbar Boolean Back , Forward, other buttons in that row, and Address
field, displaying the current URL location Boolean N/A (always defaults to the value of toolbar)
status Boolean Status bar at the bottom of the window
menubar Boolean Menu bar at the top of the window (File, Edit, View, Go,
etc.) scrollbars Boolean N/A (always defaults to “yes”)
resizable Boolean N/A (always defaults to “yes”)
width Pixels Window’s width in pixels
height Pixels Window’s height in pixels
Trang 21Web Page Programming with HTML,DHTML &
JavaScript/Session 9/ 21 of 21
Document Object
It represents the HTML document in a given browser window
and is used to retrieve information about the document
Trang 22Web Page Programming with HTML,DHTML &
JavaScript/Session 9/ 22 of 21
History Object
This object provides a list of the URL's most recently
visited by the client
Example, history's "back()" method cause the
window to again display the immediately previous
Trang 23Web Page Programming with HTML,DHTML &
JavaScript/Session 9/ 23 of 21
Location Object
This object maintains information about the current URL It
provides a method that causes the window's current URL to be
Trang 24Web Page Programming with HTML,DHTML &
JavaScript/Session 9/ 24 of 21
Navigator Object
The navigator object does not belong to JavaScript’s bulk of browser objects It is an independent object, just like the Math object This object combines various methods and properties providing information related to the user’s software
For example, you can use this object to detect the user’s browser, platform, plug-ins, and many other essential pieces of information.
Trang 25Web Page Programming with HTML,DHTML &