Transcript Document

Javascript
Document Object Model
PHPto use JavaScript
How
XHTML
Javascript
 JavaScript can be embedded into your html pages in a couple of
CGI
 in <script> elements
in both <head> and <body> elements of
HTML
page
Java
 in event attributes ofperl
appropriate elements
 by importing an external file <script
CSS
XML
type="text/javascript"
src="source.js"></script>
ways
 JavaScript URLs
 javascript:code
 javascript:alert( "Hello, World! ")
 If no value is returned, current document will not be modified
PHP
Document
Object Model
XHTML
Javascript
 Used for HTML
and XML documents
CGI
 SpecifiesHTML
the elements of a document that
JavaScript code has Java
access to
perl
 DOM0 supported by mostCSS
browsers
XML
Subset of DOM1
DOM
PHP
XHTML
Javascript
CGI
HTML
Java
perl
CSS
XML
PHP
Client-Side
JavaScript
XHTML
Javascript
 Browser provides
environment for code
CGI
to run
HTML
 The Window object Java
serves as a global
object and perl
global execution context
CSS
Represents Window
or
frame
that displays a
XML
document
Window contains a Document object
 Uses event-driven programming model
PHP
Execution
Sequence
XHTML
 JavaScript Javascript
code is executed once as the
html file is read into theCGI
browser
HTML
 Code is executed as Java
th document is
perl
parsed
CSS
in order it appears
in
the
HTML
code
XML
 Event handlers provide dynamic behavior
event handlers are attributes of objects such
as input elements
PHP Lifetimes
XHTML
Javascript
 Window object
representing top-level
CGI
window of
browser
exists
as
long
as
HTML
window exists
Java
Window isperl
restored to default state when a
CSS
new DocumentXML
is loaded
 Variables exist persist only as long as the
Document that defines them exists
PHP
Event
handlers
XHTML
 onclick Javascript
- button elements, <a>,
CGI
<area>
HTML
Java
 onmousedown, onmouseup
perl
 onmouseover, onmouseout
CSS
XML
 onchange
 onsubmit, onreset
 onload, onunload
The Window Object
PHP
XHTML
 Methods
 closed
Javascript  open(), close()
 status, defaultStatus
 alert(), confirm(),
CGI
prompt()
 document
HTML
 focus(), blur()
 self, window
Java
 moveBy(), moveTo()
 parent, top
perl
 print()
 opener
CSS

scrollBy(),
ScrollTo()
XML
 name
 Properties
 history
 frames[]
 navigator (browser info)
 setInterval(),
clearInterval()
 for repeated actions
 setTimeout, clearTimeout
 for single action
PHP
The
Navigator
Object
XHTML
Javascript
 appName
 appVersion
HTML
 userAgent
perl
 appCodeName
 platform
CGI
Java
XML
CSS
PHP
The
Document
Object
XHTML
Javascript
 alinkColor, linkColor, vlinkColor
 anchors[ ], applets[ ], forms[ ],







 open()
CGI  close()
Java  write()
images[ ], links[
]
HTML
bgColor, fgColor
perl
cookie
domain
XML
lastModified
referrer
title
location, URL
 writeln()
CSS
PHP
Document
Arrays
XHTML
 Each of theJavascript
arrays in the Document
propertiesHTML
is an array ofCGI
objects of the
appropriate type Java
perl
 Order corresponds to the order
the objects
CSS
XMLdocument
appear in the HTML
 HTML elements can be given a name
attribute. The name can be used in the
code instead of indexing into the array
PHP
Forms
XHTML
Javascript
 A Form object
contains an array of
CGI
elements.HTML
Javacorrespond to the
 The individual elements
perl
input elements in the form.
CSS
XML
 Each element can have event handlers
associated with it.
PHP
Images
XHTML
 The imagesJavascript
array contains all the inline
images inHTML
the documentCGI
an image has a src property
Java which can be
perl
changed by
the JavaScript code
CSS
XML
images can have
onmouseover, onmouseout
event handlers
You can create image variables in the code to
pre-load image files
Links
PHP
XHTML
 Array containing all the
hypertext links in the
document Javascript
 Link objects have same properties
CGI as Location
HTML
object
Java
 text property contains text between <a> and
perl
CSS
XML
 Links can have event
handlers associated with
</a>
them
 onmouseover, onmouseout, onclick
 Hyperlinks can be dynamically modified
PHP
Anchors
XHTML
Javascript
 Anchors are
named locations in an
CGI
<a name="label"></a>
Java
perl is string containing text
text property
CSS
between <a> and
</a>
XML
HTML document
HTML
PHP
OtherXHTML
Arrays
 applets list Javascript
all the applets in the document
CGI
JavaScript
code
can
call
the
public
methods
HTML
of the applet
Java
perl other types of date
 embeds represent
CSS
XML
embedded in the
document
audio, video, …
this data requires the presence of an
appropriate viewer
PHP
Miscellaneous
Objects
XHTML
Javascript
 Screen object
give access to information
CGI colorDepth
about display - height, width,
HTML
 Location object represents
Java a URL - href,
perlpathname, search
protocol, host,
CSS
 History object -XML
script does not have
access to URLs for previously visited
web sites but can use back() and
forward() to traverse them
PHP
Cookies
XHTML
 A cookie isJavascript
a small amount of named data
CGI
stored byHTML
the browser and
associated with
a particular web siteJava
provide a perl
way of saving state of a web page
CSS
last for currentXML
session by default
 Server-side programs use cookies
 JavaScript can manipulate cookie data
PHP
Sources
XHTML
 Web Design Javascript
and Programming by Paul S. Wang
and Sanda S. Katila
CGI
 JavaScriptHTML
The Definitive Guide by David
Java
Flanagan
perl
XML
CSS