What happens if you have the same parameter sname to perform a Window.Open () method, what happens? Like the window generated by HTML, if you define a name already existing window, the Open () method will simply use the existing window instead of opening a new. Take a look at the script programs below:
Execute the above statement, the browser will open a new window name "WIN" and display the page at www.javascript.com. Article 2 statements Replace the current window content for the page www.docjs.com. The following statement produces two different windows to display their respective content:
If you do not specify the name of the new window, the browser automatically generates a new window. This also applies to "_blank", but the empty string is another thing. There are several important differences for Internet Explorer and Navigator, as follows:
The following line will not be used, just listed. If you want a named window, give a name (not ""). If you don't want to name, you just don't specify this parameter, or use a special Target location "_blank".
An important point of the open () method is that the open () method is almost always called in the form of Window.Open () (even if Window represents a global object so that it can be completely omitted. Since the Document object also has an Open () method, when we want to open a new window, specifying the Window object will be clear and necessary. In the event processing, you must specify Window.Open () without simply use Open (). Due to the scope limit of the static object in JavaScript, there is no option to Document.Open () without the OPEN () call of the specified object name. For example, when an event process of an HTML button occurs, the range contains button objects, form objects, document objects, and window objects. Thus, if one event processor references the Open () method, the identifier is aborted in the document object, and the event processor opens a new document instead of opening a new window.
For the sake of reference sub-windows, the results of Window.Open () should be assigned to a variable. If the window is successfully created, Window.Open () returns a new window object, or returns NULL indicates that the creation fails (for example due to insufficient memory). If your script needs to reference the elements of the new window, the return value is very important. However, when the new window is opened, there is no "parent-child" relationship. Take a look at the following statement:
Here, we allocate a variable value called Recenttips. If you call the Window.Open () method in the function, you must omit the VAR keyword because the variable should be globally. Otherwise, the reference to Window is located in the local variable, and it cannot be accessed after the function is executed. The following statement displays the URL of the new window in an Alert dialog:
In the previous section, you have seen how to open a new window using the HTML links and forms. We can name the window by specifying a Target property or assigning a value to the Name property of the Window object. But how can I tell the existing window through its HTML name? The answer is simple. If you perform a URL parameter with an empty string and a Window.Open () method where the window name is stored, the reference to this window will be returned. Take a look at the link code below: CNET
When the following statement is executed, a reference to a new window is obtained:
Let's try again. Click this link CNET, but it is loaded, click the button below:
This button actually retrieves the name of the window called "news" and modifies the URL of that window. Note that if you do not click on the link before clicking the button, a new, empty window is loaded (because the specified window name does not exist). Remember, no matter what the document in the window, the window always keeps its name. Below is this button related HTML and JavaScript code: