JavaScript Window Function Guide Close window

zhaozj2021-02-08  230

JavaScript Window Function Guide Close window

(Author: hear the wind compiler 2001 at 11:35 on January 19)

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, then close it immediately: win = window.open ("http://www.docjs.com/", "js"); win.close (); each browser The window is clearly written with a Window object, so when you want to quote 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 the Window object, because the current window The existence is the default: location.href = "http://www.docjs.com/"; pay attention, Self is equivalent to Window, so self.close () is actually equal to Window.Close (). Window.location.href = "http://www.docjs.com/"; Close Window.close () Close 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: Click on the link below to open a new window, where the content is tryclose.html: launch window (with javascript) Launch Window (with html) 1st link using JavaScript Window.Open () method to open a window, the second link simply use the target property to achieve the same purpose: Launch WINDOW (with JavaScript)
launch window tryclose.html Display a button, it is responsible for performing Window.Close () Method:

When you click on the first link to open a new window, the browser "remember "It is generated by a scriptor. 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, when the user clicks on the mouse anywhere, the window is turned off. The following effects are implemented using JavaScript on the window. First, please see the code to open a new window: