The Window object in JS and its method

Source: Internet
Author: User

Window.location Object

The Window.location object is used to obtain the address (URL) of the current page and redirect the browser to a new page. The Window.location object can be written without using the window prefix.

Location.hostname returns the domain name of the web host

Location.pathname returns the path and file name of the current page

Location.port returns the port of the web host (80 or 443)

Location.protocol returns the Web protocol used (HTTP///https://)

Window.location.href= "Http://www.xxxxxxxx.net"; Backward function after jump
 Window.location.replace ("Http://www.xxxxxxxx.net"); No back function after jump
window.open ("Http://www.xxxxxxxx.net"); Open links in a new window, generally used for simple pop-up pages, are now basically blocked out

Window.location.reload (); Refreshes the current page.

Parent.location.reload (); Refresh Father object (for frame)

Opener.location.reload (); Refreshes the parent window object (for single-open windows)

Top.location.reload (); Refreshes the topmost object (for multiple open windows)

Window.history Object

The Window.history object contains the history of the browser. The Window.history object can be written without using the window prefix.

Window.history.back ()-Load the previous URL in the History list, as in the browser, click the Back button,

Window.history.forward ()-Loads the next URL in the history list. Same as clicking the button in the browser forward

Window.navigator Object

The Window.navigator object contains information about the visitor's browser, and the information from the Navigator object is misleading and should not be used to detect the browser version because:

    • Navigator data can be changed by browser user
    • Some browsers will identify errors for the test site
    • The browser cannot report a new operating system that is later than the browser published

The Window.navigator object can be written without using the window prefix.

Window.navigator.appCodeName returns the code name of the browser.

Window.navigator.appName returns a string representing the browser name.

Window.navigator.appMinorVersion returns the minor version number of the browser. The property is a read-only string. only IE is valid.

Window.navigator.userAgent returns a string representing the browser name and version number.

Window.navigator.platform returns the string for the browser platform ("Win32", "Win16", "WinCE", "mac68k", "MACPPC", "HP-UX", "SunOS", etc.).

Window.navigator.cpuClass returns information about the CPU ("x86", "68K", "Alpha", "PPC", etc.). only IE is valid .

Window.navigator.browserLanguage returns the language type of the browser. only IE is valid.

Window.navigator.systemLanguage returns the language type of the system. only IE is valid.

Window.navigator.userLanguage Userlanguage Returns the language type of the user environment. only IE is valid.

Window.navigator.cookieEnabled returns the authenticity value of whether the cookie is available.

Window.navigator.onLine returns whether the network can be connected to the authenticity value.

Window.navigator.javaEnabled () Returns the authenticity value of whether Java is available.

Window.navigator.userProfile the object that holds the user information. Has addReadRequest () doreadrequest () getattribute () clearrequest () and other methods.

Window.navigator.taintEnabled () Whether the authenticity value of the data can be encrypted. only IE is valid.

Some other methods of the Window object

SetInterval () and SetTimeout () are the two methods of the HTML DOM window object.

Window.setinterval ()-interval specifies the number of milliseconds to execute the specified code continuously.

Window.settimeout ()-executes the specified code after pausing the specified number of milliseconds

The Window.clearinterval () method is used to stop the function code executed by the SetInterval () method.

The Window.cleartimeout () method is used to stop executing the function code of the SetTimeout () method.

Window.alert ()-warning boxes are often used to ensure that users can get some information. When the warning box appears, the user needs to click the OK button to continue the operation.

Window.prompt ()-The confirmation box is used to enable users to verify or accept certain information. When the confirmation box appears, the user needs to click the OK or Cancel button to continue the operation. If the user clicks Confirm, then the return value is true. If the user clicks Cancel, the return value is false.

Window.confirm ()-The prompt box is often used to prompt the user to enter a value before entering the page. When the prompt box appears, the user needs to enter a value and then click the Confirm or Cancel button to continue the manipulation. If the user clicks Confirm, then the return value is the value entered. If the user clicks Cancel, the return value is null.

window.open ()-Open a new window

Window.close ()-Close the current window

Window.moveto ()-Move the current window

Window.resizeto ()-Adjusts the size of the current window

Window.frameelement Gets the host node of the current document IFRAME element

window.open () method parameters

window.open (' page.html ', ' newwindow ', ' height=100, width=400, Top=0, left=0, Toolbar=no, Menubar=no, Scrollbars=no, Resizable=no, Location=no, Status=no ')//The sentence is written in a line of code
Parameter explanation:
window.open the command that pops up the new window;
The filename of the ' page.html ' pop-up window;
The name of the ' NewWindow ' pop-up window (not the file name), not required, available empty ' ' instead;
height=100 window height;
width=400 window width;
The pixel value of the Top=0 window from the top of the screen;
The pixel value of the left=0 window from the left side of the screen;
Toolbar=no whether the toolbar is displayed, yes is displayed;
Menubar,scrollbars represents the menu bar and scroll bar.
Resizable=no whether the window size is allowed to change, yes is allowed;
Location=no whether the address bar is displayed, yes is allowed;
Status=no whether the information in the status bar is displayed (usually the file is already open), yes is allowed;

The Window object in JS and its method

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.