JavaScript Browser Object

Source: Internet
Author: User

First, what are the browser objects?

The main browser objects are: History object, location address object, Document object, Window Object Browser object,Navigator object (information of client browser), screenobject (Information on the client screen).

TwoHistory Object

The history object is created automatically by the scripting engine in the browser and consists of a series of URLs. These URLs are URLs that the user has accessed within a browser window.

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.

Properties of the History object

Length Returns the number of URLs in the browser history list

Methods of the History object


Back () load the previous URL in the history list


The back () method loads the previous URL in the history list, if one exists. The effect of calling this method is equivalent to clicking the Back button.


History.back ()


Forward () load the next URL in the history list


The forward () method can load the next URL in the history list. The effect of calling this method is equivalent to clicking the Forward button.


History.forward ()


void Go (any URL) loads a specific page in the history list


The Go () method can load a specific page in the History list.


History.go (Number|url)


Description: The URL parameter uses the URL to be accessed, or a substring of the URL. The number parameter uses the relative position of the URL to be accessed in the history's URL list.


ThreeLocation Address Object
The location object is stored in the Position property of the Window object, which represents the Web address of the document that is currently displayed in that Windows. Its href attribute holds the full URL of the document, and the other attributes describe each part of the URL, respectively.

Location Object
Protocol Sets or returns the protocol for the current URL.
Hostname Sets or returns the host name of the current URL.
Port Sets or returns the port number of the current URL.
Host Sets or returns the host name and port number of the current URL.
Pathname Sets or returns the path portion of the current URL.
Hash Sets or returns the URL (anchor) starting with the pound sign (#).
Search Sets or returns the URL (query section) starting with the question mark (?).
Href Sets or returns the full URL.

Method of the Location object

void assign (String URL) Loads a new document.
void Reload (Boolean flag) Reloads the current document. True reload, false does not reload


Location.reload (Force)
Note: If the method does not specify a parameter, or if the parameter is false, the browser detects whether the document on the server has changed. If the document has changed, reload () will download the document again. If the document does not change, the method will load the document from the cache


Replace () Replaces the current document with a new document.


Description: The Replace () method does not generate a new record in the history object. When you use this method, the new URL overwrites the current record in the history object.


Document Object

Window Browser Object
Window object


The Window object is the top-level object in the BOM hierarchy. It represents a browser window or a frame


Window object is a global object, to refer to the current window does not need special syntax, you can use the properties of the Window object as a global variable, you can use the method of the Windows object as a function.


Method of the Window object


Alert (String message) pops up a warning dialog box. The parameter content is a warning prompt.


Confirm (String message) pops up a confirmation dialog box. The parameter content is a prompt. The return value is a Boolean value that is true by the OK option, and false for the Cancel option.


Prompt (String message,string value) pops up an input dialog box. The message parameter indicates that value is the default value in the Input dialog box and can be changed by entering a value. The return value is the contents of the String Input dialog box.




The SetInterval () method invokes a function or evaluates an expression by the specified period (in milliseconds) until Clearinterval () is called or the window is closed.


SetInterval (CODE,MILLISEC)


Code required. The function to invoke or the code string to execute. Millisec must. The time interval, in milliseconds, between periodically executing or calling code.


Return value: A value that can be passed to Window.clearinterval () to suppress periodic execution of code




The Clearinterval () method cancels the timeout set by SetInterval (). The parameter of the Clearinterval () method must be the ID value returned by SetInterval ().


Clearinterval (Id_of_setinterval)


Parameter id_of_setinterval is the ID value returned by setinterval ()


The SetTimeout () method is used to call a function or evaluate an expression after a specified number of milliseconds.


SetTimeout (CODE,MILLISEC)


Code required. The JavaScript code string to execute after the function to invoke. Millisec required. The number of milliseconds to wait before executing the code.


Return value: A value that can be passed to Window.cleartimeout () to cancel the deferred execution of code.


The Cleartimeout () method cancels the timeout set by the SetTimeout () method.


Cleartimeout (Id_of_settimeout)


The parameter id_of_settimeout is the ID value returned by settimeout (). This value identifies the deferred execution code block to be canceled.
The open () method opens a new browser window or looks for a named window.


window.open (String url,string name,string Features,boolean Replace)


Url An optional string that declares the URL of the document to display in a new window. If this argument is omitted, or if its value is an empty string, then the new window will not display any documents.

Name An optional string that is a comma-delimited list of features, including numbers, letters, and underscores that declare the name of the new window. This name can be used as the value of the tag <a> and <form> property target. If the parameter specifies a window that already exists, the open () method no longer creates a new window, but simply returns a reference to the specified window. In this case, the features will be ignored.

Features An optional string that declares the characteristics of the standard browser to be displayed for the new window. If this argument is omitted, the new window will have all the standard features.


Replace An optional Boolean value. Specifies whether the URL loaded into the window creates a new entry in the window's browsing history or replaces the current entry in the browsing history. The following values are supported: True-url replaces the current entry in the browsing history. False-url creates a new entry in the browsing history.




Parameter features for window features


Width=pixels The width of the document display area of the window. measured in pixels.
Height=pixels The height of the document display area of the window. measured in pixels.
Left=pixels The x-coordinate of the window. measured in pixels.
Top=pixels The y-coordinate of the window.
Directories=yes|no|1|0 Whether to add a catalog button. The default is yes.
Location=yes|no|1|0 Whether the Address field is displayed. The default is yes.
Menubar=yes|no|1|0 Whether the menu bar is displayed. The default is yes.
Scrollbars=yes|no|1|0 Whether scroll bars are displayed. The default is yes.
Status=yes|no|1|0 Whether to add a status bar. The default is yes.
Titlebar=yes|no|1|0 Whether the title bar is displayed. The default is yes.
Toolbar=yes|no|1|0 Whether to display the browser's toolbar. The default is yes.
Resizable=yes|no|1|0 Whether the window can be adjusted for size. The default is yes.
Fullscreen=yes|no|1|0 Whether to use full-screen mode to display the browser. The default is No.
Channelmode=yes|no|1|0 Whether to use the theater Mode Display window. The default is No.


The close () method is used to close the browser window.


Window.close ()




The Moveby () method moves the specified pixel relative to the current coordinates of the window.


void Window.moveby (number x,number y);
X: The number of pixels to move the window to the right;
Y: The number of pixels to move the window down.


The MoveTo () method moves the upper-left corner of the window to a specified coordinate.

Window.moveto (number X,number y);


X: The x-coordinate of the new position of the window;
Y: the y-coordinate of the new position of the window.


The Resizeby () method adjusts the size of the window according to the specified pixels.


void Resizeby (number width, number height);


Width required. The number of pixels to increase the width of the window. Can be a positive, negative value.
Height is optional. The number of pixels to increase the height of the window. Can be a positive, negative value.


The Resizeto () method adjusts the window size to the specified width and height.


void Resizeto (number width,number height);


Width required. The width of the window you want to adjust to. measured in pixels.
Height is optional. The height of the window you want to adjust to. measured in pixels.


The Scrollby () method scrolls the page content by the specified number of pixels.


void Scrollby (number xnum,number ynum);


Xnum required. The number of pixels to scroll the document to the right.
Ynum required. The number of pixels to scroll down the document.


The ScrollTo () method scrolls the content to the specified coordinates.


void ScrollTo (number xpos,number ypos);


Xpos required. The x-coordinate of the document to display in the upper-left corner of the window's document display area.
Ypos required. The y-coordinate of the document to display in the upper-left corner of the window's document display area.


The properties of the Window object;


Whether the Boolean window.closed window is closed.


The Closed property returns a Boolean value that declares whether the window has been closed. This property is read-only.


When the browser window is closed, the Windows object that represents the window does not disappear, it will continue to exist, but its closed property will be set to true.
String Window.name Sets or returns the window name


The Name property can set or return a string that holds the name of the window. The name is specified in the open () method when the window is created or with the Name property of a <frame> tag. The name of the window can be used as a value for the target property of a <a> or <form> tag. Using the target property in this way declares that the hyperlink document or form submission results should appear in the specified window or frame.


Windows Window.opener returns a reference to the window that created this window.


The opener property is a readable, writable property that returns a reference to the Window object that created it.


Note: Only the Operner property of the Window object that represents the top-level window is valid, and the Operner property of the Window object that represents the frame is invalid.


Window window.parent return to parent windows


Window Window.self returns a reference to the current window. Equivalent to the Window property.


Window Window.top returns to the topmost of the ancestors ' windows.


This property returns a read-only reference to a top-level window. If the window itself is a top-level window, the top property holds a reference to the window itself. If the window is a frame, then the top property references the top-level window that contains the frame.
Number Window.screenleft The x-coordinate of the upper-left corner of the window on the screen
Number Window.screenx The x-coordinate of the upper-left corner of the window on the screen


Number Window.screentop the y-coordinate of the upper-left corner of the window on the screen
Number Window.screeny the y-coordinate of the upper-left corner of the window on the screen


HTMLDocument Window.document Read-only reference to the Document object


History Window.history Read-only references to history objects


Location window.location the Location object used for the window or frame.


Navigator Window.navigator Read-only references to Navigator objects


Screen Window.screen read-only references to screen objects


Array Window.frames Returns a collection of all named frames in the window.




Navigator Object
The Navigator object is created automatically by the script runtime engine in the browser and contains information about the client browser.

appCodeName Returns the code name of the browser.
AppName Returns the name of the browser.
AppVersion Returns the platform and version information for the browser.
cookieenabled Returns a Boolean value that indicates whether cookies are enabled in the browser.
Platform Returns the operating system platform on which the browser is running.
UserAgent Returns the value of the user-agent header of the server sent by the client.


To test the Navigator property value


document.write ("navigator.appcodename Browser code Name:" + navigator.appcodename);
document.write (' document.write ("Navigator.appname Browser name:" + navigator.appname);
document.write (' document.write ("Navigator.appversion returns the browser platform and version information:" + navigator.appversion);
document.write (' document.write ("navigator.cookieenabled cookie is enabled:" + navigator.cookieenabled);
document.write (' document.write ("Navigator.platform returns the operating platform running the browser:" + navigator.platform);
document.write (' document.write ("Navigator.useragent returns the value of the user-agent header of the server sent by the client:" + navigator.useragent);
document.write ('

Screen Object


The Screen object is created automatically by the script runtime engine in the browser, and contains information about the client display screens. The screen property of each Window object refers to a screen object. The screen object holds information about the display of the browser screens.


Properties of the Screen object


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).
ColorDepth Returns the bit depth of the palette on the target device or buffer.
Height Returns the height of the display screen.
Width Returns the width of the display screen.

document.write ("Screen resolution:");
document.write (screen.width + "*" + screen.height);
document.write ("<br/>");
document.write ("Available View Area:");
document.write (screen.availwidth + "*" + screen.availheight);
document.write ("<br/>");
document.write ("Color depth:");
document.write (screen.colordepth);

The browser object model refers to the running environment of the script, the set of objects that the browser provides for the script, and the organization relationship between the groups of objects.

The Window object implements the operation of the browser window and access to the framework.

The Location object provides information about the page address and how to manipulate the address.

The history object is used to represent a collection of the addresses of the pages that the browser window has ever visited, and contains methods to implement a backward or jump forward within the range of addresses.

The Navigator object is used to obtain information about the client on which the browser resides.

The screen object is used to get information about the client screens.

JavaScript Browser Object

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.