Home >Web Front-end >JS Tutorial >Properties and events of Window object in JavaScript_javascript skills

Properties and events of Window object in JavaScript_javascript skills

WBOY
WBOYOriginal
2016-05-16 15:23:341420browse

Window object

The Window object represents an open window in the browser.

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

Note: There is no public standard for the window object, but it is supported by all browsers.

windows object properties

Properties Description
closed Returns whether the window has been closed.
defaultStatus Set or return the default text in the window status bar.
document A read-only reference to the Document object. See Document object .
history Read-only reference to the History object. Please parameter History object .
innerheight Returns the height of the document display area of ​​the window.
innerwidth Returns the width of the document display area of ​​the window.
length Set or return the number of frames in the window.
location A Location object for a 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.
outerwidth Returns the outer width of the window.
pageXOffset Set or return the X position of the current page relative to the upper left corner of the window display area.
pageYOffset Set or return the Y position of the current page relative to the upper left corner of the window display area.
parent Return to the parent window.
Screen Read-only reference to the Screen object. Please parameter Screen object .
self Returns a reference to the current window. Equivalent to the Window property.
status Set the text of the window status bar.
top Return to the top-level ancestor window.
window The window attribute is equivalent to the self attribute, which contains a reference to the window itself.
  • screenLeft
  • screenTop
  • screenX
  • screenY
Read only integers. Declares the x-coordinate and y-coordinate of the upper left corner of the window on the screen. IE, Safari, and Opera support screenLeft and screenTop, while Firefox and Safari support screenX and screenY.

windows object methods

Method Description
alert() Shows an alert box with a message and a confirm button.
blur() Remove keyboard focus from the top-level window.
clearInterval() Cancel the timeout set by setInterval().
clearTimeout() Cancel the timeout set by the setTimeout() method.
close() Close the browser window.
confirm() Displays a dialog box with a message and confirm and cancel buttons.
createPopup() Create a pop-up window.
focus() Give keyboard focus to a window.
moveBy() Moves the window by specified pixels relative to its current coordinates.
moveTo() Move the upper left corner of the window to a specified coordinate.
open() Open a new browser window or find a named window.
print() Print the contents of the current window.
prompt() Display a dialog box that prompts the user for input.
resizeBy() Resize the window according to the specified pixels.
resizeTo() Resize the window to the specified width and height.
scrollBy() Scroll content according to the specified pixel value.
scrollTo() Scroll the content to the specified coordinates.
setInterval() Call a function or evaluate an expression at a specified period (in milliseconds).
setTimeout() Calls a function or calculated expression after a specified number of milliseconds.

Different running environments have different "top-level objects", and in the browser environment, the top-level object is the window object. window refers to the current browser window.

Example: var a = 1;

window.a; //1

1. Properties of window object.

(1) window.name attribute

window.name is used to set the name of the current browser window of the browser. The characteristic is that this attribute remains unchanged after the browser is refreshed.

(2) window.innerHeight property, window.innerWidth property

These two properties return the height and width of the browser window occupied by the css layout of the web page. The values ​​of these two properties include the height and width of the browser's scroll bar.

(3) window.pageXoffset property and window.pageYoffset property.

window.pageXoffset returns the horizontal scrolling distance of the page. window.pageYoffset returns the vertical scroll distance of the page.

(4) iframe element

window.iframe returns an array-like object.

(5) screen object

Shows device information.

// Display the height of the device in pixels
screen.height
// 1920
// Display the width of the device, in pixels
screen.width
// 1080

2. Events of window object.

(1) onerror event.

The oonerror event is an old-fashioned standard way of catching Javascript errors in web pages.

(2) alert(), prompt(), confirm()

are all methods used by browsers to interact with users. They will pop up different dialog boxes.

Example: alert("Hello World");

alert(); The pop-up dialog box has only one "OK" button, which is often used to notify the user of certain information.

Example: var result = prompt('What is your age?', 25)

prompt(); The pop-up dialog box has an input box that requires the user to enter information, and has two buttons: "OK" and "Cancel". This method is often used to obtain data entered by the user.

Example: var result = confirm("How are you doing?");

confirm(); The confirm method returns a Boolean value. If the user clicks "OK", it returns true; if the user clicks "Cancel", it returns false.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn