This article mainly describes the properties and methods of the HTML DOM window object.
Directory
1. Description: Describes the HTML DOM window object.
2. Properties: Describes the properties of the Window object. Such as: References to console, Document, history, location, and navigator objects.
3. Method: Describes the method of the Window object. Such as: Get focus, change scroll bar, set timer and so on.
1. Introduction
The Window object represents the windows, labels, or frames that the browser opens (if the current page contains multiple iframe, a Window object is created for each IFRAME).
The Window object is not instantiated, and the call properties and methods are all static members of the window.
When you call a member of the Window object, you can omit the previous window. such as: Window.alert () can be written as alert ().
2. Properties
ReadOnly Applicationcache Applicationcache : Returns the application cache object for the window.
ReadOnly boolean closed : Returns whether the window has been closed.
ReadOnly console console: Returns a reference to the Consol object and operates on the browser console.
readonly int devicepixelratio : Returns the device pixel ratio, which is the physical pixel of the current display and the device independent pixel (DIP) ratio.
ReadOnly Document Document : Returns the Document object for the current window.
ReadOnly Element frameelement : If the current window is in a <iframe>, this property returns the IFRAME. Returns null if in the top-level window.
ReadOnly window[] frames : Returns an array that contains all the frames within the window.
ReadOnly history : Returns a History object. The history of the current page can be manipulated, such as: forward, backward and so on.
ReadOnly long innerheight : Returns the current window to display the height of the HTML document, in px (pixels).
ReadOnly long innerwidth : Returns the current window to display the width of the HTML document, in px (pixels).
ReadOnly long length : Returns the number of frames contained within the window, that is, the number of frames.
ReadOnly location : Returns a Location object. You can manipulate the URL of the current page, such as navigating to a new page, getting URL information, and so on.
ReadOnly localstorage localstorage : Returns a key/value pair of stored storage objects that persist until deleted by the user.
String name : Sets or gets the name of the current window.
ReadOnly Navigator Navigator : Returns a Navigator object. The current browser can be manipulated. such as: Get browser name, version information, operating system platform information, and so on.
Window Openner : Returns a reference to the original window that opens the current window. If the current window is opened by another window, Window.opener retains a reference to that window. If the current window is not open by another window, the property returns NULL.
ReadOnly long outerheight : Returns the total height of the current browser, in px (pixels). Contains a range of toolbars, scrollbars, browser borders, and so on.
ReadOnly long outerwidth : Returns the total width of the current browser, in px (pixels). Contains a range of toolbars, scrollbars, browser borders, and so on.
ReadOnly long Pagexoffset : Returns the distance that the document is scrolled horizontally, in px (pixels).
ReadOnly long pageYOffset : Returns the distance, in px (pixels), of the document's longitudinal scrolling.
ReadOnly window Parent: Returns the current window. If the current window is a top-level window, returns the current window itself. If the current window is a frame window, it returns its parent window.
ReadOnly screen : Returns a Screen object. You can manipulate the screen, such as: get the screen height, width.
ReadOnly long ScreenX : Returns the x-coordinate of the browser on the screen.
ReadOnly long ScreenY : Returns the y-coordinate of the browser on the screen.
ReadOnly long SCROLLX : Returns the distance that the document is scrolled horizontally, in px (pixels). Same as the Pagexoffset property.
ReadOnly long scrolly : Returns the distance, in px (pixels), of the document's longitudinal scrolling. Same as the pageYOffset property.
readonly window self: Returns a reference to the current Window object.
ReadOnly sessionstorage sessionstorage : Returns a key/value pair stored storage object that continues until the end of the current browsing session.
readonly window Top : Returns the top-level windows of the current window. If the current window itself is already top-level, it returns itself. If the current window is a frame window, returns the top-level window that contains it (the parent simply returns to the parents window).
readonly window window: Returns the Windows object.
3. Methods
void AddEventListener(String eventtype,function EventListener): Registers the window with the time. EventType event type, such as: click. EventListener: An event-triggered function or object.
void alert(String msg): pops up a warning box containing MSG and a confirmation button.
String Atob(String base64str): Decodes a 64-encoded string into a string.
void Blur(): Removes focus from the current window.
String btoa(String str): Encodes a string into a 64 encoding.
void clearinterval(Long Intervalhandle): Stops intervalhandle the specified setinterval ().
void cleartimeout(Long Timeouthandle): Stops timeouthandle the specified settimeout ().
void Close(): Closes the current window. You can only close a window opened by a script, such as: A element opens a new page.
Boolean confirm(String msg): Displays a dialog box with a message along with a confirmation button and a Cancel button. Click the Confirm button to return True and click the Cancel button to return false.
void Focus(): The current window gets focus.
void Moveby(Long deltax, long DeltaY): Causes the Open () method to create a window that, at its own position, moves deltax pixels horizontally, moving vertically deltay pixels.
void MoveTo(long x, long y): causes the window created by the open () method to move to the x, Y coordinates.
Window open(string URL, string target, string features, String replace): Creates a new window.
parameter: ①url {string}: A new window loaded URL. If not specified, "about:blank"will be used. ②target {string} : Name of the new window. If not specified, "_black"will be used. Note This value is not a window caption. ③features {string} Optional: Represents the properties of a new window, such as: Window functions and toolbars. The string cannot contain any whitespace characters, and the attributes are separated by commas. Return value: {window} returns a reference to a new window.
Method Details
void print (): invokes the browser's Print button.
String prompt(string msg): pops up an input box that displays MSG information and includes a OK button and a Cancel button. This input box blocks the page, clicks the OK button to return the input, and then clicks the Cancel button to return null.
void Resizeby(Long deltawidth, long deltaheight): Causes the Open () method to create a window, in its own position, to increase the width of deltawidth pixels, Increase the height of deltaheight pixels.
void Resizeto(long width, long height): The window created by the open () method becomes width and height becomes height.
void Scrollby(Long deltawidth, long deltaheight): Scrolls horizontally deltawidth pixels, scrolling vertically deltaheight pixels, based on the current scrolling.
void ScrollTo(long width, long height): Scrolls horizontally across the width pixel distance, scrolling vertically to height pixel distance.
Long setinterval(function fn, long time): Executes the specified function every interval (in milliseconds).
parameters: ①fn {function}: functions that need to be executed. ②time {long}: Sets the specified function to execute every number of milliseconds. Units: milliseconds. Return value: {long} returns a number. You can cancel the execution of this function by calling Window.clearinterval ().
Method Details
Long setTimeout(function fn, long time): Executes the pointing function after a certain number of milliseconds.
parameters: ①fn {function}: functions that need to be executed. ②time {long}: Sets the number of milliseconds after which the specified function executes. Units: milliseconds. Return value: {long} returns a number. You can cancel the execution of this function by calling Window.cleartimeout ().
Method Details
================================== Series article ==========================================
This article: 4.2 HTML DOM Window object
Web Development Road Series articles
HTML DOM Window Object