Summary of the methods and properties of the window object [Summary--window object]

The window object has the following methods:

open close alert confirm prompt setTimeout clearTimeout setInterval clearInterval moveBy moveTo resizeBy resizeTo scrollBy scrollTo find back forward home stop print blur focus captureEvent enableExternalCapture disableExternalCapture handleEvent  releaseEvent routeEvent scroll

1. open method

Syntax format: window.open(URL, window name, window style)

Function: Open a new window and load the webpage with the specified URL address in the window.

illustrate:

The open method is used to open a new browser window and load a specified URL address in the new window;

When the open method opens a new browser window, you can also specify the name of the window (the second parameter);

When the open method opens a new browser window, you can also specify the style of the window (the third parameter). The window style has the following options, and these options can be selected multiple times. If multiple options are selected, the options are separated by commas:

toolbar: Specifies whether the window has a standard toolbar. When the value of this option is 1 or yes, it means that there is a standard toolbar; when the value of this option is 0 or no, it means that there is no standard toolbar;

location: specify whether the window has an address toolbar, the value and meaning of the option are the same as toolbar;
directories: specify whether the window has a link toolbar, the value and meaning of the option are the same as toolbar;
status: specify whether the window has a status bar, the value of the option and the meaning is the same as the toolbar;
menubar: specifies whether the window has a menu, the value and meaning of the options are the same as the toolbar;
scrollbar: specifies whether there is a scroll bar when the current window document is larger than the window, the value and meaning of the options are the same as the toolbar;
resizable: specifies the window Whether the size can be changed, the value and meaning of the options are the same as toolbar;
width: specify the width of the window in pixels, which has been replaced by innerWidth;
height: specify the height of the window in pixels, which has been replaced by innerHeight;
outerWidth: in pixels Specifies the outer width of the window in units;
outerHeight: specifies the outer height of the window in
pixels; left: specifies the position of the window from the left side of the screen
in pixels; top: specifies the position of the window from the top of the screen in pixels;
alwaysLowered: The specified window is hidden behind all windows, and the value and meaning of the option are the same as toolbar;
alwaysRaised: the specified window is floated above all windows, and the value and meaning of the option are the same as toolbar;
dependent: the opened window is specified as a child window of the current window , and closes with the closing of the parent window, the value and meaning of the option are the same as the toolbar;
hotkeys: set the hotkey for safe exit in a new window without a menu bar, the value and meaning of the option are the same as the toolbar;
innerHeight: set the pixel height of the document in the window;
innerWidth: Set the pixel width of the document in the window;
screenX: Set the pixel length of the window from the left border of the screen;
screenY: Set the pixel length of the window from the upper border of the screen;
titleBar: Indicate whether the title bar is visible in the new window, options The value and meaning of z-look are the same as those of toolbar;
z-look: indicates that when the window is activated, it cannot float on top of other windows. The value and meaning of the options are the same as those of toolbar.
The open method returns a reference to the window.

Tip: This method is often used to automatically open another window when a web page is opened.

2. close method

Syntax format: window.close()

Function: The close method is used to automatically close the browser window.

3. alert method

Syntax format: window.alert (prompt string)

Function: A warning box will pop up, and the prompt string text will be displayed in the warning box.

4. confirm method

Syntax format: window.confirm (prompt string)

Function: Display a confirmation box and display a prompt string in the confirmation box. When the user clicks the "OK" button, the method returns true, and when the user clicks "Cancel", it returns false.

5. prompt method

Syntax format: window.prompt (prompt string, default text)

Function: display an input box, display the prompt string in the input box, display the default text in the input text box, and wait for the user to input, when the user clicks the "OK" button, return the string input by the user, when click When the "Cancel" button is pressed, a null value is returned.

6. setTimeout method

Syntax format: window.setTimeout(code character expression, milliseconds)

Function: Timing setting, when the specified number of milliseconds is reached, the code character expression is automatically executed.

7. clearTimeout method

Syntax format: window.clearTimeout (timer)

Function: Cancel the previous timing setting, the parameter is the return value when set with setTimeout.

8. setInterval method

Syntax format: window.setInterval(code character expression, milliseconds)

Function: After setting a time interval (the second parameter), repeatedly execute the content of the "code character expression"

9. clearInterval method

Syntax format: window.clearInterval (time interval)

Function: Cancel the timing set by setInterval. The parameter is the return value of the setInterval method.

10. moveBy method

Syntax format: window.moveBy (horizontal displacement, vertical displacement)

Function: Move the specified window according to the given pixel parameters. The first parameter is the pixels by which the window is moved horizontally, and the second is the pixels by which the window is moved vertically.

11.moveTo method

Syntax format: window.moveTo(x,y)

Function: Move the window to the specified specified coordinates (x, y).

12. resizeBy method

Syntax format: window.resizeBy(horizontal, vertical)

Function: Change the current window to the specified size (x, y). When the value of x and y is greater than 0, it is expanded, and when it is less than 0, it is reduced.

13. resizeTo method

Syntax format: window.resizeTo(horizontal width, vertical width)

Function: Change the current window to (x, y) size, where x and y are width and height respectively.

14. scrollBy method

Syntax format: window.scrollBy (horizontal displacement, vertical displacement)

Function: Scroll the content in the window by the given displacement. When the parameter is positive, scroll forward, otherwise scroll backward.

15. scrollTo method

Syntax format: window.scrollTo(x,y)

Function: Scroll the content in the window to the specified position.

16. find method

Syntax format: window.find()

Function: When this method is triggered, a "find" dialog window will pop up and allow the user to search for a string in the page that triggered the find method.

Note: This attribute is not supported in IE5.5 and Netscape6.0.

17. back method

Syntax format: window.back()

Function: Simulate the user to click the "back" button on the browser to move the page to the previous page of the browser.

Description: This operation can only be performed when there is a previous page on the current page.

Note: IE5.5 does not support this method, but Netscape6.0 supports it.

18. forward method

Syntax format: window.forward()

Function: Simulate the user to click the "forward" button on the browser to move the page to the next page of the browser.

Description: This operation can only be performed when there is a next page on the current page.

Note: IE5.5 does not support this method, but Netscape6.0 supports it.

19. home method

Syntax format: window.home()

Function: Simulate the user to click the "Home" button on the browser to transfer the page to the specified page.

Note: IE5.5 does not support this method, but Netscape6.0 supports it.

20. stop method

Syntax format: window.stop()

Function: Simulate the user to click the "Stop" button on the browser to terminate the download operation of the browser.

Note: IE5.5 does not support this method, but Netscape6.0 supports it.

21. print method

Syntax format: window.print()

Function: Simulate the user to click the "Print" button on the browser to notify the browser to open the print dialog to print the current page.

22. blur method

Syntax format: window.blur()

Function: Remove the focus from the window. Care must be taken when used with the focus method, as it may cause the focus to constantly move in and out.

23. focus method

Syntax format: window.focus()

Function: Make the window get the focus. Care must be taken when combined with the blur method, as it may cause the focus to move in and out

24. captureevent method

Syntax format: window.captureevent(event)

window.captureevent(event1|event2|...|eventn)

Function: Capture all events of the specified parameter. Because of the ability to capture events that are handled by the native program itself, programmers can freely define functions to handle events. If there are multiple events to be captured, separate events with a pipe character "|". The types of events that can be caught are as follows:

event.abort event.blur event.change event.click event.dblclick event.dragdrop event.error event.focus event.keydown event.keypress event.keyup event.load event.mousedown event.mousuemove event.mouseout event.mouseover event.mouseup event.move event.reset event.resize  event.select event.submit event.unload

25. enableexternalcapture事件

Syntax format: window.enableexternalcapture(event)

Function: The enableexternalcapture method is used to capture external events passed in through parameters.

26. disableexternalcapture事件

Syntax format: window.disableexternalcapture()

Function: Cancel the setting of the enableexternalcapture method and terminate the capture of external events.

27. handleevent event

Syntax format: window.handleevent(event)

Function: The event handler that triggers the specified event.

28. releaseevent event

Syntax format: window.releaseevent(event)

window.releaseevent(event1|event2|...|eventn)

Function: Release the captured events passed in through parameters, these events are set by the window.captureevent method, and the releaseable events are the same as captureevent.

29. routeevent event

Syntax format: window.releaseevent(event)

Function: Transfer all events of the captured type to the standard event processing method for processing. The events that can be transferred are the same as captureevent.

30. scroll event

Syntax format: window.scroll(x coordinate, y coordinate)

Function: Move the window to the specified coordinate position.

Properties of the window object

The window object has the following properties:

status statusbar statusbar.visible defaultstatus location locationbar locationbar.visible self name closed frames frames.length length document history innerheight innerwidth menubar menubar.visible opener outerheight outerwidth pagexoffset pageyoffset parent  personalbar  personalbar.visible scrollbar scrollbar.visible toolbar toolbar.visible top 

1. status attribute

Syntax format: window.status=string

Function: Set or give the current display information of the status bar in the browser window.

Tip: You can use this property to set browser window status bar information.

2. statusbar property

Syntax format: window.statusbar.property

Function: The statusbar property itself is also an object, which is used to access its own visible property to determine whether the status bar is visible.

Note: ie5.5 browser does not support this property.

3. statusbar.visible property

Syntax format: window.statusbar.visible

Function: Check whether the status bar is visible, if it is visible, return true, otherwise return false.

Note: ie5.5 browser does not support this property.

4. defaultstatus property

Syntax format: window.defaultstatus[=string]

Function: The defaultstatus attribute value is the default display information of the status bar in the browser window

5.location property

Syntax format: window.location=url

Function: Give the url information of the current window or specify the url of the opened window.

  expand:

  1. Set or get the file name or path specified by the object.

  alert(window.location.pathname)

  2. Set or get the entire URL as a string.

  alert(window.location.href);

  3. Set or get the port number associated with the URL.

  alert(window.location.port)

  4. Set or get the protocol part of the URL.

  alert(window.location.protocol)

  5. Set or get the segment after the pound sign "#" in the href attribute.

  alert(window.location.hash)

  6. Set or get the hostname and port number of the location or URL.

  alert(window.location.host)

  7. Set or get the part of the href attribute that follows the question mark.

  alert(window.location.search)

  8. Get the value of the variable (truncate the part after the equal sign)

   var url = window.location.search;

  //    alert(url.length);

  //    alert(url.lastIndexOf('='));

  var loc = url.substring(url.lastIndexOf('=')+1, url.length);

  9, used to get the domain name of the current web page

  var domain = document.domain;

6. locationbar property

Syntax format: window.locationbar.property

Function: The locationbar property can also be regarded as a sub-object. This property is used to obtain its own visible property to determine whether the location bar is visible. So far, this property has only one sub-property: visible.

Note: ie5.5 does not support this property.

7. locationbar.visible property

Syntax format: window.locationbar.visible

Function: Returns whether the location bar is visible, if visible, returns true, otherwise returns false.

Note: ie5.5 does not support this property.

8. The self attribute

Syntax format: window.self. method

window.self.property

Function: This property contains the flag of the current window. Using this property, it can be ensured that when multiple windows are opened, the function or property in the current window can be called correctly without confusion.

9. name attribute

Syntax format: window.name=name

Function: Returns the window name, which is given when a new window is created by the window.open() method. In the javascript1.0 version, this property can only be used to read the window name, and in the javascript1.1 version, this property can be used to specify a name for a window that is not created by the window.open() method.

10. closed property

Syntax format: window.closed

Function: The closed property is used to return whether the instance of the specified window has been closed. If it is closed, it returns true, otherwise it returns flase.

11. frames property

Syntax format: window.frames["frame name"]

window.frames[value]

Function: The frames attribute is an array used to store each subwindow (frame) instance created by the element in the document. The subscript can be either the sequence number or the name specified by the name attribute of the frame element. use.

12. frames.length property

Syntax format: window.frames.length

Function: The frames.length attribute is used to give the number of child window (frame) instances in the document.

13. length property

Syntax format: window.length

Function: The length property returns the number of child windows in a window, which is the same as the value of the window.frame.length property.

14. document property

Syntax format: window.document.event window.document.method window.document.property

Function: The child object document of the window object is the core object of javascript, and an instance is created when the body element is encountered in the script.

15. history property

Syntax format: window.history[value] window.history.method() window.history.property

The child object history of the window object is one of the core objects of javascript, and this property contains an array of the names and urls of the pages that have been visited.

16. innerheight property

Syntax format: window.innerheight=number

Function: Returns or specifies the pixel height of the document in the browser window. This height does not include any toolbars and page decoration heights that make up the window.

Note: ie5.5 does not support this property.

17. innerwidth property

Syntax format: window.innerheight=number

Function: Returns or specifies the pixel width of the document in the browser window, excluding any toolbars and page decoration widths that make up the window.

Note: ie5.5 does not support this property.

18. menubar property

Syntax format: window.menubar.property

Function: The menubar property can also be regarded as a sub-object. This property is used to obtain its own visible property to determine whether the menu bar is visible. So far, this property has only one sub-property: visible.

Note: ie5.5 does not support this property.

19. menubar.visible property

Syntax format: window.menubar.visible

Function: The menubar.visible property is used to return whether the menu bar is visible, if it is visible, it returns true, otherwise it returns false.

Note: ie5.5 does not support this property.

20. opener property

Syntax format: window.opener window.opener. method window.opener. property

Function: The opener property is associated with the parent window that opened the window. When accessing the operer property in the child window, the parent window is returned. Through this property, you can use the methods and properties of the parent window object.

21. outerheight property

Syntax format: window.outerheight

Function: The outerheight property is used to access the pixel height of the browser window, which includes the height of the toolbar and decorative edges.

Note: ie5.5 does not support this property.

22. outerwidth property

Syntax format: window.outerwidth

Function: The outerwidth property is used to access the pixel width of the browser window, which includes the width of the toolbar and decorative edges.

Note: ie5.5 does not support this property.

23. pagexoffset property

Syntax format: window.pagexoffset=value

Function: Specify the current horizontal pixel position of the upper left corner of the document in the browser window in the window. Before using moveto to move, you can use this property to decide whether you need to move the window. Because this property returns the current position of the visible document relative to the entire page.

Note: ie5.5 does not support this property.

24. pageyoffset property

Syntax format: window.pageyoffset=value

Function: Specify the current vertical pixel position of the upper left corner of the document in the browser window in the window. Before using moveto to move, you can use this property to decide whether you need to move the window. Because this property returns the current position of the visible document relative to the entire page.

Note: ie5.5 does not support this property.

25. parent property

Syntax format: window.parent.frames[value] window.parent.framesname

Function: Access the parent window where each child window (multi-frame) is located.

26. personalbar attribute

Syntax format: window.personalbar.property

Function: The personalbar property is itself an object, and is used to access its own visible property to determine whether the personal bar is visible.

Note: ie5.5 does not support this property.

27. personalbar.visible property

Syntax format: window.personalbar.visible

Function: Determine whether the personal column is visible, if it is visible, return true, otherwise return false.

Note: ie5.5 does not support this property.

28. scrollbars property

Syntax format: window.scrollbars.property

Function: The scrollbars property is itself an object, which is used to access its own visible property to determine whether the scrollbar is visible

Note: ie5.5 does not support this property.

29. scrollbars.visible property

Syntax format: window.scrollbars.visible

Function: scrollbars.visible is used to determine whether the scroll bar is visible, if it is visible, it returns true, otherwise it returns false.

Note: ie5.5 does not support this property.

30. toolbar property

Syntax format: window.toolbar.property

Function: The toolbar property itself is also an object, which is used to access its own visible property to determine whether the toolbar is visible.

Note: ie5.5 does not support this property.

31. toolbar.visible property

Syntax format: window.toolbar.visible

Function: The toolbar.visible property is used to check whether the toolbar is visible, if it is visible, it returns true, otherwise it returns false.

Note: ie5.5 does not support this property.

32. top attribute

Syntax format: window.top.frames[value] window.top.framename window.top.method()

window.top.property

Function: The top property of the window object is used to contain information about the topmost window of all child windows (multi-frames) loaded into the browser.

  expand:

  1. Set or get the file name or path specified by the object.

  alert(window.location.pathname)

  2. Set or get the entire URL as a string.

  alert(window.location.href);

  3. Set or get the port number associated with the URL.

  alert(window.location.port)

  4. Set or get the protocol part of the URL.

  alert(window.location.protocol)

  5. Set or get the segment after the pound sign "#" in the href attribute.

  alert(window.location.hash)

  6. Set or get the hostname and port number of the location or URL.

  alert(window.location.host)

  7. Set or get the part of the href attribute that follows the question mark.

  alert(window.location.search)

  8. Get the value of the variable (truncate the part after the equal sign)

   var url = window.location.search;

  //    alert(url.length);

  //    alert(url.lastIndexOf('='));

  var loc = url.substring(url.lastIndexOf('=')+1, url.length);

  9, used to get the domain name of the current web page

  var domain = document.domain;

  1. Set or get the file name or path specified by the object.

  alert(window.location.pathname)

  2. Set or get the entire URL as a string.

  alert(window.location.href);

  3. Set or get the port number associated with the URL.

  alert(window.location.port)

  4. Set or get the protocol part of the URL.

  alert(window.location.protocol)

  5. Set or get the segment after the pound sign "#" in the href attribute.

  alert(window.location.hash)

  6. Set or get the hostname and port number of the location or URL.

  alert(window.location.host)

  7. Set or get the part of the href attribute that follows the question mark.

  alert(window.location.search)

  8. Get the value of the variable (truncate the part after the equal sign)

   var url = window.location.search;

  //    alert(url.length);

  //    alert(url.lastIndexOf('='));

  var loc = url.substring(url.lastIndexOf('=')+1, url.length);

  9, used to get the domain name of the current web page

  var domain = document.domain;

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326311173&siteId=291194637