JavaScript Common Browser objects

Source: Internet
Author: User

1. Classification system of objects

When each HTML document is loaded into the browser, the browser creates a series of hierarchical object architectures that reflect the properties of the HTML document.

The following objects are included in each HTML page:

Navigator: Contains the name of the navigator being used, the version attribute, the client-supported MIME type property, and the "plug-in" type of the client installation.

window: The highest-level object, with the properties of the entire window, and the corresponding window object in the child window in each frame.

Document: Contains attributes that are based on the content of documents, such as title, BackgroundColor, links, and form.

Location: Contains properties based on the current URL.

History: Contains URLs that the client has previously requested.

When you reference a property, you must specify all ancestors of the property. For example, reference to the value of Text1 in form MyForm must be written as:

Document. MyForm.Text1.Value

2. Key Browser objects

In HTML pages, the most useful JavaScript objects are: window, Frame, document, Form, location, history, and navigator objects. I'll talk about these objects separately here.

window and Frame objects

The Window object is the ancestor of all other objects of the HTML document and is a collection of browser window and window properties. When multiple frames are defined in a Web page with frame and frameset, each frame corresponds to a frames object. The properties and methods of the frame object and the Window object are the same, just different from the corresponding region in the browser.

The methods of the Window object are:

Open and close: Open and close a browser window; You can define size, content, button bars, anchor areas, and other properties.

Alert: Displays a dialog box with warning messages.

Confirm: Displays a confirmation dialog with OK and Cancel buttons.

Prompt: Displays a prompt dialog box with an input text box.

Blur and Focus: Set and remove input focus in one window.

Scroll: Scrolls the window to the specified coordinates.

SetTimeout: Evaluates an expression after a specified number of times.

In addition, the location and Status properties in window can accomplish some useful tasks:

By assigning a value to the Location property, the browser goes to the specified URL, as the user types a URL address, such as: location= "http://www.yesky.com" will cause the browser to go to the Yesky home page.

Assigning a value to the Status property displays the specified information in the State bar at the bottom of the browser.

Document Object

The Write and Writeln methods of the Document object are believed to be familiar to readers through previous introductions. In addition, the document object reflects many of the attributes of the HTML document, including: Background (BgColor), text (fgcolor), link colors (linkcolor, alinkcolor, and Vlinkcolor), and LastModified ( The date the document was last modified), referrer (previously visited URL), url (the URL of the current document), and so on.

The cookie property allows the user to read and set the value of the cookie.

The Document object is an "ancestor" object for all anchor, applets, area, Form, Image, Link, plugin, and so on.

Form Object

When you use <form> and </form> to define a form in an HTML document, the form object is created. Because there can be more than one form in a home page, each form object uses an array or

The table in sole name to differentiate. Such as:

Document.forms[1]html the second form in the document (the first form is forms[0]);

Document.forms[0].elements[1]html the second component of the first form in a document (this can be a button or inputtext, etc.).

Location Object

The properties of the location object are based on the value of the current URL. such as: hostname is the domain name of the server and summary document.

There are two methods of location objects:

Reload: Forces the reload of the current document.

Replace: Forces the specified URL document to be loaded and overwrites the current history.

History Object

The history object retains the historical record of the user browsing the web in a string array. The current, next, and previous properties of the history object can be used to access existing, next, and previous historical items, as well as to access other historical items with the history array.

The go method of the History object is used to move the browser to the specified historical record. For example:

History.go (-2) load the first two URLs;

History.go (0) reload the current page.

Navigator Object

The Navigator object contains information about the current browser, such as: The AppName property specifies the name of the browser, and the AppVersion property specifies the version information for the browser.

There are two methods of Navigator objects:

javaenabled: Specifies whether Java is supported.

Taintenabled: Specifies whether to use data scrambling. About data scrambling I'll explain in a later article.

The following is a list of Navigator predefined object arrays for your reference:

  

JavaScript Common Browser objects

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.