JavaScript supplement: BOM (Browser object model)

Source: Internet
Author: User

Some common objects. Detailed reference manual.

First, Window object

Window objects represent open windows in the browser.

If the document contains frames (<frame> or <iframe> tags), the browser creates a Window object for the HTML document and creates an additional window object for each frame.

Note: There is no public standard applied to the Window object, but the object is supported by all browsers.

Properties Description
Closed Returns whether the window has been closed.
Defaultstatus Sets or returns the default text in the window's status bar.
Document A read-only reference to the Document object. (See objects)
Frames Returns all named frames in the window. The collection is an array of window objects, each of which contains a frame in the windows.
History A read-only reference to the History object. Please use the parameter history object.
Innerheight Returns the height of the window's document display area.
Innerwidth Returns the width of the window's document display area.
Length Sets or returns the number of frames in a window.
Location The location object used for the window or frame. See Location object.
Name Sets or returns the name of the window.
Navigator A read-only reference to the Navigator object. Please parameter Navigator object.
Opener Returns a reference to the window that created this window.
Outerheight Returns the outer height of the window, containing the toolbar and scroll bar.
Outerwidth Returns the outer width of the window, including the toolbar and scroll bar.
Pagexoffset Sets or returns the X position of the current page relative to the upper-left corner of the window display area.
pageYOffset Sets or returns the Y position of the current page relative to the upper-left corner of the window display area.
Parent Returns the parent window.
Screen A read-only reference to the Screen object. Please parameter screen object.
Screenleft Returns the x-coordinate relative to the screen window
Screentop Returns the y-coordinate relative to the screen window
ScreenX Returns the x-coordinate relative to the screen window
ScreenY Returns the y-coordinate relative to the screen window
Self Returns a reference to the current window. Equivalent to the Window property.
Status Sets the text of the window's status bar.
Top Returns the topmost parent window.
Method Description
Alert () Displays a warning box with a message and a confirmation button.
Blur () Move the keyboard focus away from the top-level window.
Clearinterval () Cancels the timeout set by SetInterval ().
Cleartimeout () Cancels the timeout set by the SetTimeout () method.
Close () Close the browser window.
Confirm () Displays a dialog box with a message and a confirmation button and a Cancel button.
Createpopup () Create a pop-up window.
Focus () Give the keyboard focus to a window.
Moveby () The specified pixel can be moved relative to the current coordinates of the window.
MoveTo () Moves the upper-left corner of the window to a specified coordinate.
Open () Open a new browser window or look for a named window.
Print () Prints the contents of the current window.
Prompt () Displays a dialog box to prompt the user for input.
Resizeby () Resizes the window by the specified pixels.
Resizeto () Adjusts the size of the window to the specified width and height.
Scroll ()
Scrollby () Scrolls the content by the specified pixel value.
ScrollTo () Scrolls the content to the specified coordinates.
SetInterval () Invokes a function or evaluates an expression by the specified period (in milliseconds).
SetTimeout () Invokes a function or evaluates an expression after the specified number of milliseconds.

Second, Navigator object

The Navigator object contains information about the browser. Note: There is no public standard applied to the Navigator object, but this object is supported by all browsers.

Properties description
appcodename return The code name of the browser.
appminorversion Returns the secondary version of the browser.
appName Returns the name of the browser.
appversion returns the platform and version information for the browser.
browserlanguage Returns the language of the current browser.
cookieenabled Returns a Boolean value that indicates whether cookies are enabled in the browser.
cpuclass Returns the CPU level of the browser system.
onLine Returns a Boolean value that indicates whether the system is in offline mode.
platform returns the operating system platform on which the browser is running.
systemlanguage Returns the default language used by the OS.
useragent Returns the value of the user-agent header of the server sent by the client.
userlanguage Returns the natural language setting for the OS.
Method Description
Javaenabled () Specifies whether Java is enabled in the browser
Taintenabled () Specifies whether the browser enables data tainting

Third, Screen object

The Screen object contains information about the client display screens.

Note: There is no public standard applied to the screen object, but this object is supported by all browsers.

Properties description
availheight Returns the height of the display screen (in addition to the Windows taskbar).
availwidth Returns the width of the display screen (in addition to the Windows taskbar).
bufferdepth Sets or returns the bit depth of the palette.
colordepth Returns the bit depth of the palette on the target device or buffer.
devicexdpi Returns the horizontal dots per inch of the display screen.
deviceydpi Returns the number of vertical points per inch of the display screen.
fontsmoothingenabled Returns whether the user has enabled font smoothing in the Display control Panel.
height Returns the height of the display screen.
logicalxdpi Returns the regular number of points that show the horizontal direction of each inch of the screen.
logicalydpi Returns the regular number of points that display the vertical direction of each inch of the screen.
pixeldepth Returns the color resolution (bits per pixel) of the display screen.
updateinterval Sets or returns the refresh rate for the screen.
width Returns the width of the display screen.

The screen property of each Window object refers to a screen object. The screen object holds information about the display of the browser screens. The JavaScript program will use this information to optimize their output to meet the user's display requirements. For example, a program can choose to use a large image or a small image depending on the size of the display, and it can choose to use a 16-bit color or a 8-bit color based on the color depth of the display. In addition, the JavaScript program can position the new browser window in the middle of the screen based on information about the screen size.

Iv. The history of the object

The History object contains the URLs that the user has visited (in a browser window).

The history object is part of the Window object and can be accessed through the Window.history property.

Note: There is no public standard applied to the history object, but this object is supported by all browsers.

Properties Description
Length Returns the number of URLs in the history list
Method Description
Back () Load the previous URL in the history list
Forward () Load the next URL in the history list
Go () Load a specific page in the history list

The History object was originally designed to represent the window's browsing histories. But for privacy reasons, the History object no longer allows scripts to access the actual URLs that have been accessed. The only features that remain used are the back (), forward (), and Go () methods.

V. Location Object

The Location object contains information about the current URL.

The Location object is part of the Window object and is available through window. The Location property to access it.

Note: There is no public standard applied to the Location object, but this object is supported by all browsers.

Properties Description
Hash Returns the anchor part of a URL
Host Returns the host name and port of a URL
Hostname Returns the host name of the URL
Href Return the full URL
Pathname Returns the URL path name.
Port Returns the port number used by a URL server
Protocol Returns a URL protocol
Search Returns the query part of a URL
Method Description
Assign () Load a new document
Reload () Reload the current document
Replace () Replace the current document with a new document

VI. JavaScript Pop-up window

You can create three message boxes in JavaScript: A warning box, a confirmation box, and a prompt box.

Window.alert ("sometext"), Window.confirm ("sometext"), (The return value is True or FALSE, received through a variable), window.prompt ( "sometext", "defaultvalue"); (returns a string, received through a variable). \ nthe line is wrapped.

Seven, JavaScript timer

By using JavaScript, we have the ability to execute code after a set interval of time, not immediately after the function is called. We call this a timing event.

It is easy to use timing events in JAVASCRITP, and two key methods are: SetInterval ()-interval specifies the number of milliseconds to execute the specified code continuously. SetTimeout ()-executes the specified code after pausing the specified number of milliseconds.

Syntax: var intervalvariable=Window.setinterval ("JavaScript function",milliseconds); To terminate the timing event, use Window.clearinterval (intervalvariable)

var timeoutvariable=window.settimeout ("JavaScript function ", number of milliseconds ); The Purge event uses window.cleartimeout (timeoutvariable).

Eight, JavaScript Cookies

The escape function is added first: an escaped or encoded string used to return a string. Use Unescape () to decode. The method does not encode ASCII letters and numbers, nor does it encode the following ASCII punctuation marks: * @-_ +. / 。 All other characters will be replaced by escape sequences. This function works by finding a sequence of characters in the form%xx and%uxxxx (x for hexadecimal digits), decoding with Unicode characters \U00XX and \uxxxx replacing such sequences of characters. ECMAScript v3 against using this method, the application uses decodeURI () and decodeuricomponent () to replace it.

Syntax: document.cookie= "Username=john Doe; Expires=thu, Dec 12:00:00 GMT; path=/"; Using this statement does not clear the current cookie, but instead directly adds the cookie above. The first semicolon precedes the cookie key-value pair, the second is the expiration time, and the third belongs to which address.

The method for reading cookies is var x = Document.cookie; Gets the string type.

The method for modifying cookies is document.cookie= "Username=john Smith; Expires=thu, Dec 12:00:00 GMT; path=/"; The old cookie will be overwritten.

The way to delete a cookie is to set the expires parameter to the previous time, which immediately expires. Expired cookies are automatically deleted.

Note: The Document.cookie property looks like an ordinary text string, in fact it is not. Even if you write a full cookie string in Document.cookie, when you re-read the cookie information, the cookie information is displayed in the form of a name = value pair, with different key-value pairs separated by semicolons and carriage returns. If you set up a new cookie, the old cookie will not be overwritten. The new cookie is added to the document.cookie (so there is no cookie with the same name).

JavaScript supplement: BOM (Browser object model)

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.