Sei sulla pagina 1di 24

Document object

Document Object provides the foundation for


creating dynamic web pages.
The Document Object provides the ability for a
JavaScript script to access, manipulate, and
extend the content of a web page dynamically.
The JavaScript Document object is the
container for all HTML HEAD and BODY objects
associated within the HTML tags of an HTML
document. Which includes the properties of
every form, link and anchor as well as global
Document properties such as background and
foreground colors.

Document properties
Property

Description

alinkcolor

The color to be used when displaying activated links in


the document

Anchors

An array of anchor objects present in the document

applets

An array of Java Applet objects embedded into the


document

bgColor

The background color of the document

fgColor

The foreground color (i.e., the color of the text in the


document)

Cookie

The cookie, if any, assosiated with the document.

domain

The current domain of the document

Forms

An array of the Forms objects contained in the


document.

Images

An Array of Image objects contained the document

lastModif
ed

The date that the document was last modified

linkColor

The color to be used when displaying links in the

Document properties
Propert
y

Description

title

The title of the document (corresponds to the HTML


<title> tag)

URL

The URL of the current document

vlinkCol The color to be used when displaying links in the


or
document which
have been visited by the current user

Anchors Property
This property is an array containing
references to all the named Anchor
objects in the
current document.
Syntax:
Document.anchor

Forms Property
This property is an array containing
references to all the Form objects in
the current document
Syntax:
document.forms[formID]

Links Property
This property is an array containing
references to all the Area and Link
objects in the current
document.
Syntax: document.links[linkID]

Cookie Property
This property is a string that returns
a report detailing all visible and unexpired cookies
that are associated with the specified
document.
Syntax:
Document.cookie

Domain Property
This property sets or returns the
domain name of the server from
which the document
originated.
Syntax: document.domain =
domaininfo

Title Property
This property returns the documents
name as defined between the
<TITLE></TITLE> tags.
Syntax: document.title
URL Property
This property is used to retrieve the
documents full URL.
Syntax: document.URL

bgColor Property
This property defines a documents background
color. The colorinfo argument is a string
that can contain either the hexadecimal
definition of the color or its literal description.
Syntax: document.bgColor = colorinfo
fgColor Property
This property defines a documents foreground
(text) color. The colorinfo argument is a
string that can contain either the hexadecimal
definition of the color or its literal description.
Syntax: document.fgColor = colorinfo

alinkColor Property
This property defines the color of an active link.
The colorinfo argument is a string that
can contain either the hexadecimal definition of
the colour or its literal description.
Syntax: document.alinkColor = colorinfo

vlinkColor Property

This property defines the colour of any visited links in the


document. The colorinfo
argument is a string that can contain either the hexadecimal
definition of the color or its
literal description.
Syntax: document.vlinkColor = colorinfo

Document Methods
Method

Description

open()

Opens the output stream to the document for


writing

close()

Closes the output stream to the document to


prevent further writing

write()

Appends text to the document.

writeln()

Appends text to the document followed by a


newline character

getElementByID()

Accesses the first element with the specified


id

getElementsByName
Accesses all elements with a specified name
()
getElementsByTagNa
Accesses all elements with a specified tagname
me()

Open method
The open() method opens a stream to collect the
output from any document.write or
document.writeln methods.
NOTE: If a document already exists in the target,
it will be cleared. If this method has no
arguments, a new window with about:blank is
displayed.
Syntax:
document.open(mimetype,replace)

Write method
The write() method writes HTML
expressions or JavaScript code to a
document.
Note: Multiple arguments
(exp1,exp2,exp3,...) can be listed and
they will be appended to the
document in order of occurrence.
Syntax:
document.write(exp1,exp2,exp3,
....)

Writeln methods
The writeln() method is identical to
the write() method, with the addition
of writing a new line character after
each expression.
Syntax:
document.writeln(exp1,exp2,exp3,....
)

Close methods
The close() method closes an output
stream opened with the
document.open method, and
displays the collected data.
Syntax:
Document.close()

Window object

Window Object Properties


Property Description
Returns a Boolean value indicating whether a window
closed
has been closed or not
Sets or returns the default text in the statusbar of a
defaultStat
window
us
document Returns the Document object for the window
Returns an array of all the frames (including iframes) in
frames
the current window
history
Returns the History object for the window
Sets or returns the inner height of a window's content
innerHeigh
area
t
Sets or returns the inner width of a window's content
innerWidth
area

length
location
name
navigator
opener
outerHeight
outerWidth
pageXOffset
pageYOffset
parent

Returns the number of frames (including iframes) in a


window
Returns the Location object for the window
Sets or returns the name of a window
Returns the Navigator object for the window
Returns a reference to the window that created the
window
Sets or returns the outer height of a window, including
toolbars/scrollbars
Sets or returns the outer width of a window, including
toolbars/scrollbars
Returns the pixels the current document has been
scrolled (horizontally) from the upper left corner of the
window
Returns the pixels the current document has been
scrolled (vertically) from the upper left corner of the
window
Returns the parent window of the current window

screen

Returns the Screen object for the window


Returns the x coordinate of the window relative
screenLeft
screen
Returns the y coordinate of the window relative
screenTop
screen
Returns the x coordinate of the window relative
screenX
screen
Returns the y coordinate of the window relative
screenY
screen
self
Returns the current window
status
Sets the text in the statusbar of a window
top
Returns the topmost browser window

to the
to the
to the
to the

Window Object Methods


Method

blur()

Description
Displays an alert box with a message and an OK
button
Removes focus from the current window

clearInterval()

Clears a timer set with setInterval()

clearTimeout()

Clears a timer set with setTimeout()

close()

createPopup()

Closes the current window


Displays a dialog box with a message and an OK and a
Cancel button
Creates a pop-up window

focus()

Sets focus to the current window

moveBy()

Moves a window relative to its current position

moveTo()

Moves a window to the specified position

open()

Opens a new browser window

print()

Prints the content of the current window

prompt()

Displays a dialog box that prompts the visitor for

alert()

confirm()

resizeBy()

Resizes the window by the specified pixels

resizeTo()

Resizes the window to the specified width and height

scroll()

scrollBy()

Scrolls the content by the specified number of pixels

scrollTo()

Scrolls the content to the specified coordinates


Calls a function or evaluates an expression at specified
setInterval()
intervals (in milliseconds)
Calls a function or evaluates an expression after a
setTimeout()
specified number of milliseconds

Window.location
window.location.href returns the href (URL)
of the current page
window.location.hostname returns the
domain name of the web host
window.location.pathname returns the path
and filename of the current page
window.location.protocol returns the web
protocol used (http:// or https://)
window.location.assign loads a new
document

Potrebbero piacerti anche