JavaScript Window Function Guide Close window

xiaoxiao2021-03-06  38

When you create a new window, allocate the return value of the Open () method to a variable is very important. For example, the following statement is to create a new window and close it immediately:

Win = WINDOW.OPEN ("http://www.docjs.com/", "js");

Win.Close ();

Each browser window is clearly written with a Window object, so when you want to reference the current window, you should use the Window object. The following statement sets the URL of the current window:

Window.location.href = "http://www.docjs.com/";

When you place such a statement in the script, you don't need to specify a Window object, because the existence of the current window is default:

Location.href = "http://www.docjs.com/";

Note that Self is equivalent to Window, so self.close () is actually equal to Window.Close ().

Window.location.href = "http://www.docjs.com/";

close the window

Window.close () Turn off the specified browser window. If the close () function is called without a window reference, JavaScript turns off the current window. In an event handler, you must specify Window.Close () without using Close (). Due to the scope of JavaScript total static object, a close () call without object name is equivalent to document.close ().

If you perform a close () method to close a window that is not opened by the script, a confirmation dialog will have a confirmation dialog to select whether to close the window. If there is only a record in the historical list, the dialog box will not appear in the Navigator. However, if you use Close () to exit the last running browser instance, the confirmation dialog will appear. See the dialog box that appears in the 2-type browser looks like:

Click on the link below to open a new window, where the content is TryClose.html:

Launch Window (with JavaScript)

Launch Window (with HTML)

The first link uses JavaScript's Window.Open () method to open a window, and the second link simply uses the target attribute to achieve the same purpose:

launch window (with javascript)

launch window (with html)

Page TryClose.html Displays a button, it is responsible for performing a window.close () method:

When you click on the first link to open a new window, the browser "remember" It is generated by a script program. So, when you click on the button, the new window does not have to confirm that the operation is turned off. The second link is another thing, it does not use any JavaScript to open a new window, when you click the button, Internet Explorer will display a confirmation dialog. However, Navigator immediately closes this window because the new window does not have any documents in the session history.

JavaScript allows you to use a script in other windows to close another window.

Click to close the window

Many standard applications have an About dialog that is turned off when the user clicks on the mouse anywhere. The following effects are implemented using JavaScript on the window. First, see if you open the new window: