Detailed explanation of windows. open of windows. close of methods in JavaScript

  • 2021-07-06 10:07:56
  • OfStack

Detailed explanation of windows. open () method:

window. open (URL, name, features, replace) is used to load the specified URL into a new or existing window and return an Window object representing the new window. It has four optional parameters:

URL: An optional string declaring the URL of the document to be displayed in the new window. If this parameter is omitted, or if its value is an empty string, the new window will not display any documents.

name: An optional string that is a comma-separated list of features including numbers letters and underscores that declare the name of the new window. This name can be used as a tag < a > And < form > Gets or sets the value of the property target of. If this parameter specifies an existing window, the open () method uses that window directly. In this case, the features parameter specifying the window characteristics will be ignored. Reserved names: "_ blank", "_ parent", "_ top" refer to the new window display position.

features: (non-standard, it is recommended to ignore this parameter) an optional string that declares the characteristics of the standard browser to be displayed in the new window. If this parameter is omitted, the new window will have all the standard characteristics. In the following window characteristics table, we explain the format of this string in detail.

replace: 1 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. Supported values: true-URL replace the current entry in the browsing history; false-URL Creates new entries in the browsing history.

The new top-level browser window is created by the method Window. open (). When you call this method, you should store the return value of the open () call in a variable, and then use that variable to reference the new window. The opener property of the new window in turn references the window in which it was opened.

Don't confuse methods Window. open () with methods Document. open (), which have completely different functionality. To make your code clear, use Window. open () instead of open ().

Most browsers have added pop-up filtering systems. Usually the open method is invoked only when the user clicks a button or link manually. JavaScript code usually fails when it attempts to open 1 pop-up window when the browser is initially loaded (or unloaded).

Window Features (Window Features)

channelmode = yesno10 Whether to display the window in theater mode. The default is no.

directories=yesno10 Whether to add a directory button. The default is yes.

fullscreen=yesno10 Whether to display the browser in full screen mode. The default is no. Windows in full screen mode must also be in theater mode.

height = the height of the document display area of the pixels window. In pixels.

left = x coordinates of the pixels window. In pixels.

location=yesno10 whether the address field is displayed. The default is yes.

menubar=yesno10 Whether the menu bar is displayed. The default is yes.

resizable = yesno10 window is sizable. The default is yes.

scrollbars=yesno10 Whether or not the scroll bar is displayed. The default is yes.

status=yesno10 Whether to add a status bar. The default is yes.

titlebar=yesno10 Whether the title bar is displayed. The default is yes.

toolbar=yesno10 Whether the browser's toolbar is displayed. The default is yes.

top = y coordinates of the pixels window.

width = the width of the document display area of the pixels window. In pixels.

window. close () Method:

If you have already created an Window object w, you can close the window w. close (); In this window, use window. close ();

Note: The window. close () method must be explicitly called to avoid confusion with the document. close () method;

Most browsers only allow scripts to automatically close windows created by scripts. If you want to close other windows, you can use a dialog box to get the user's confirmation or cancellation; window. close () cannot close a form embedded in a window;

Even if a window is closed, the Window object representing it still exists. A closed window will have an closed property with a value of true, its document will be null, and its methods will normally no longer work.


Related articles: