Javascript-advanced object

Source: Internet
Author: User
Browser object (Navigator)

Provide information about browsers

Window object)

The window object is at the top of the object hierarchy. It provides methods and properties for processing the Navigator window.

Location)

The location object provides methods and attributes to work with the currently opened URL. It is a static object.

Historical object (History)

The History Object provides information related to the history list.

Document Object)

A document object contains objects that work with the document elements. It encapsulates these elements for programmers to use.

1. Window object
Is the largest object in Javascript, which describes a browser window. Generally, to reference its attributes and methods, you do not need to use the "window. XXX" format, but directly use "XXX ". A framework page is also a window.
Attribute:
• Name of the window, opened by its connection (<a target = "... ">) or frame page (<frame name = "... ">) or the open () method called by a window (see below. This attribute is generally not used.
• Status indicates the content displayed in the "status bar" below the window. By assigning values to status, you can change the display of the status bar.
• Opener usage: window. opener; return the window object that opens the window. Note: A window object is returned. If the window is not opened by another window, null is returned for this attribute in Netscape; "undefined" is returned for IE ). Undefined is equal to null to some extent. Note: Undefined is not a javascript constant. If you attempt to use "undefined", "undefined" is returned.
• Self refers to the window itself, which returns the same object as the window object. The most common is "self. close () ", placed in the <A> tag:" <a href = "javascript: Self. close () "> Close Window </a> ".
• Parent returns the frame Page Object of the window.
• Top return frame page Objects occupying the top of the entire browser window.
• Historical objects of history, see.
• Location address object, see.
• Document Object, see.
Method:
Open () opens a window.
Usage:
Open (<URL string>, <window name string>, <parameter string> );
Note:
• <URL string>: Describe the webpage opened in the window. If you leave it blank (''), no webpage is opened.
• <Window name string>: the name of the window to be opened (window. Name). You can use built-in names such as '_ top' and '_ blank. The name here is the same as the "target" attribute in "<a href ="... "target ="... ">.
• <Parameter string>: Describes the appearance of the Opened Window. If you only need to open a normal window, leave this string blank (''). If you want to specify the appearance, write one or more parameters in the string, separated by commas.
For example, open a clean window of 400x100:
Open ('', '_ blank', 'width = 400, Height = 100, menubar = No, toolbar = No, location = No, directories = No, status = No, scrollbars = Yes, resizable = Yes ')
Open () Parameters
• Top = # number of rows that exit the top of the screen at the top of the window
• Left = # number of records left when the left side of the window leaves the screen
• Width = # window width
• Height = # window height
• Menubar =... Is there any menu in the window? The value is yes or no.
• Toolbar =... does the window have a toolbar? The value is yes or no.
• Location =... does the window have an address bar? The value is yes or no.
• Directories =... there is no connection area in the window. The value is yes or no.
• Scrollbars =... does the window have a scroll bar? The value is yes or no.
• Status =... does the window have a status bar? values: yes or no
• Resizable =... the window cannot be adjusted. The value is yes or no.

Note: The open () method has a return value, which is the window object it opens. For example, VAR newwindow = open ('', '_ blank'); assign a new window to the" newwindow "variable, and then control the window through the" newwindow "variable.
Close () closes an opened window.
Usage:
Window. Close ()
Or
Self. Close ()
The main function is to close this window;
<Window Object>. Close (): Close the specified window. Note: If the window has a status bar, the browser will warn after calling this method: "The webpage is trying to close the window. Are you sure you want to close it ?" Then wait for the user to choose whether or not. If there is no status bar, calling this method will close the window.
In addition, the window object also has the following method:
• Blur () removes focus from the window and changes the window to an "inactive window ".
• Focus () is the focus of the window, which is changed to "activity window ". However, in Windows 98, this method can only Flash the title bar of the window and the corresponding buttons on the taskbar, prompting the user that the window is trying to get the focus.
• Scrollto () usage: [<window Object>.] scrollto (x, y); enables the window to scroll from the (x, y) points in the upper left corner of the window to the upper left corner of the window.
• Scrollby () usage: [<window Object>.] scrollby (deltax, deltay) enables the window to scroll to the right of the deltax pixel, scroll down the deltay pixel. If a negative value is obtained, it is rolled in the opposite direction.
• ResizeTo () usage: [<window Object>.] resizeTo (width, height); enables the window to be adjusted to width, width, and height.
• ResizeBy () usage: [<window Object>.] resizeBy (deltawidth, deltaheight); adjust the window size, increase the width of deltawidth pixels, and increase the height of deltaheight pixels. If the value is negative, the value is reduced.
• Alert () usage: Alert (<string>); a dialog box containing only the "OK" button is displayed, showing the content of <string>, reading the entire document and running the script will be paused until the user presses "OK ".
• Confirm () usage: Confirm (<string>); a dialog box containing the "OK" and "cancel" buttons is displayed, asking the user to make a selection, reading the entire document and running the script are paused. If you press "OK", true is returned. If you press "cancel", false is returned.
• Prompt () usage: prompt (<string> [, <initial value>]); a dialog box containing "OK" and "cancel" and a text box is displayed, when <string> content is displayed, you must enter some data in the text box. Reading the entire document and running the script are paused. If the user presses "OK", the existing content in the text box is returned. If the user presses "cancel", the return value is null. If <initial value> is specified, the default value is displayed in the text box.

Event:
Window. onload; occurs when all documents are downloaded. After all the files are downloaded, not only HTML files, but also images, plug-ins, controls, applets, and other content are downloaded. This event is a window event, but when you specify an event handler in HTML, we write it in the <body> tag.
• Window. onUnload; occurs when the user exits the document (or closes the window, or goes to another page. Like onload, it should be written in HTML and written into the <body> tag.
• Window. onresize; occurs when the window is adjusted.
• Window. onblur; occurs when the window loses focus.
• Window. onfocus; occurs when the window gets the focus.
• Window. onerror; occurs when an error occurs. Its event handler is usually called an error handler to handle errors. As mentioned above, to ignore all errors, use: function ignoreerror (){
Return true;
}
• Window. onerror = ignoreerror;

Window. onbeforeunload = "window. event. returnvalue = 'Are you sure you want to leave? '"; The dialog box Indicating whether to exit this page is displayed;

The browser parses and executes the Javascript script while loading. The onload command is executed only after loading.

And

Navigate Method

Setinterval method: execute a program cyclically;

SetTimeout method: execute a program after a period of time

Showmodaldialog

Showmodalessdialog

2. The document object is an attribute of the window and frames objects. It is a document displayed in a window or frame. It contains the content of the document from Usage: Document (current window) or <window Object>. Document (specified window)
Attribute:
• Document. Title // set the document title is equivalent to the <title> tag of HTML.
• Document. bgcolor // set the page background color
• Document. fgcolor // set the foreground color (text color)
• Document. linkcolor // The link color that has not been clicked
• Document. alinkcolor // the color of the activation Link (focus on this link)
• Document. vlinkcolor // the color of the clicked Link
• Document. url // set URL attributes to open another webpage in the same window
• Document. filecreateddate // file creation date, read-only attribute
• Document. filemodifieddate // file modification date, read-only attribute
• Document. filesize // file size, read-only attribute
• Document. Cookie // set and read cookies
• Document. charset // set the character set to simplified Chinese: gb2312
• For more information about cookies, see "use framework and cookies.
• Lastmodified the last modification date of the current document, which is a date object.
• Referrer if the current document is opened by clicking the link, the referrer returns the original URL.
• Title refers to the text defined in • Fgcolor indicates the text color of the text attribute marked by <body>.
• Bgcolor indicates the background color represented by the bgcolor attribute marked by <body>.
• Linkcolor indicates the connection color of the link Property marked by <body>.
• Alinkcolor indicates the active connection color of the alink attribute marked by <body>.
• Vlinkcolor indicates the accessed connection color of the vlink attribute marked by <body>.

Internal array object

In JavaScript, you can use forms, frames, elements, links, and anchors to facilitate operations on internal objects) array to access objects.

Example:

<A name = "anchor1" href = "test33.htm"> link to the third text </a>
<A href = "# anchor1"> first anchor1 </a>

Document. Links. Length = 2, document. Anchors. Length = 1.

Method:
• Open () open the document so that javascript can write data to the current location of the document (the location where Javascript is inserted. This method is usually not required and automatically called by javascript when necessary.
• Write (); writeln () writes data to a document. The written data is treated as standard document HTML. The difference between writeln () and write () Is that writeln () adds a line break after data is written. This line feed is only a line feed in HTML. Whether it can be a line feed displayed depends on the position where Javascript is inserted. For example, if the <PRE> label is inserted, the new line feed is also reflected in the document.
• Clear () clears the current document.
• Close () closes the document and stops writing data. If the write [Ln] () or clear () method is used, you must use the close () method to ensure that the changes can be displayed. If the document has not been fully read, that is, JavaScript is inserted in the document, you do not need to use this method.

For example, a typical pop-up update notification:
<Script language = "JavaScript">
VaR whatsnew = open ('', '_ blank', 'top = 50, Left = 50, width = 200, Height = 300, '+
'Menubar = No, toolbar = No, directories = No, location = No, '+
'Status = No, resizable = No, scrollbars = yes ');
Whatsnew.doc ument. Write ('<center> <B> Update notification </B> </center> ');
Whatsnew.doc ument. Write ('<p> last update date: 0020.8.01 ');
Whatsnew.doc ument. Write ('<p> 0020.8.01: added the "My favorites" section. ');
Whatsnew.doc ument. Write ('<p align = "right">' +
'<A href = "javascript: Self. Close ()"> close the window </a> ');
Whatsnew.doc ument. Close ();
</SCRIPT>
You can also write an HTML file and load it directly in the open () method.

Write ()

Writeln ();

Clear (); you can use the write ("") and close () methods to implement the clear function;

Createelement ();

Createstylesheet ();

<SCRIPT> the document object in the tag pair is not the same as the document object in the event function.

After document. Close (), a new document is enabled.

When writing ('</SCRIPT>'), it may be mistaken as the end mark of the first script, the solution is to change it to write ('</SC' + 'rip> ');

3. Forms []; form object document. Forms [] is an array containing all forms in the document (<form> ). To reference a single form, you can use document. forms [Index], but in general, people will do this: Add "name =" in the <form> tag "... "" attribute, then directly use "document. <form name> "can be referenced.
Form Object Attributes
Name: return the form name, that is, the <form name = "..."> attribute.
Action returns/sets the form submission address, that is, the <form action = "..."> attribute.
Method returns/sets the form submission method, that is, the <form method = "..."> attribute.
Target Returns/sets the window returned after the form is submitted, that is, the <form target = "..."> attribute.
Encoding returns/sets the encoding method of the content submitted by the form, that is, the <form enctype = "..."> attribute.
Length returns the number of elements contained in the form.
Method
Reset () resets the form. This is the same as pressing the reset button.
Submit () submit the form. This is the same as pressing the submit button.
Event
Onreset; onsubmit

4. Anchors array object

Links array object

Images array object

Scripts array object

Applets array object

All Array

Stylesheets array object

Body object,

4. Window Object Attributes

Location object:

Window. Location. href = "" is equivalent to widnow. navigate.

Widnow. Location. Replace ("")

Widnow. Location. Reload

Event object:

Altkey attributes

Ctlkey attributes

Shiftkey attributes

Coordinates related to the event Source

Clientx and clienty attributes

Screenx and screeny attributes

Offsetx and offsety attributes

X and Y attributes

Returnvalue attributes

The cancelbubble attribute. If it is set to true, an event is blocked from being passed up.

Srcelement attributes

Keycode attribute, code value

Frames array object

How to access frame window objects:

Window. Parent. Frame [1]...

Window. Parent. Frame ["framename1"]...

Window. Parent ["framename1"]...

Window. Parent. framename1 .....

Window. Parent. item [1]...

Window. Parent. item ["framename1"]...

Top attributes

 

Screen Object

ClipboardData object

History Object

Navigator object

Document Object

Body object event:

Onselectstart

Onscroll

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.