JavaScript Window Function Guide to open a new window

zhaozj2021-02-08  215

JavaScript Window Function Guide to open a new window

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

When you click on a simple link to open a new window, you don't have any control over the new window. The browser opens a new window with the default feature. In addition, you can't use JavaScript to reference the new window's Window object, so you can't manipulate the properties of the new window. Take a look at the JavaScript statement: window.open ("http://www.docjs.com/", "win"); this statement opens a new window, display the page http://www.docjs.com/. The name of the new window is assigned to "WIN". The basic syntax of the open () method of the Window object is: Window.Open (SURL, SNAME); 2 parameters are optional, if you do not want to specify the URL or window name, use an empty string (""). SURL is A string that specifies the URL to display the document. If you do not specify a URL, an empty window is generated. Sname is the defined window name, which is used for

or tag attribute. In Internet Explorer 5 and later, if this value is "_search", the SURL will be opened in the browser search area. 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: window.open ("http://www.javascript.com/", "win"); window.open ("http://www.docjs.com/", "win") Declare 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: window.open ("http://www.javascript.com/", "Win1"); window.open ("http://www.docjs.com / "," win2 "); 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:

WINDOW.OPEN ("http://www.cn.com/"); Window.Open ("http://www.usatoday.com/"); Internet Explorernavigator Opens 2 Different Windows Open 2 Different Windows

WINDOW.OPEN ("http://www.cn.com/" "" _blank "); window.open (" http://www.usatoday.com/ "," _blank "); Internet Explorernavigator Opens 2 different Open 2 different windows

WINDOW.OPEN ("http://www.cn.com/", ""); window.Open ("http://www.usatoday.com/", ""); Internet Explorernavigator Opens 2 different windows Only open a window, the name is empty ("") 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 (). 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. The return value should be assigned to a variable for the result of Window.Open () in order to appropriately reference the sub-window. 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: var recenttips = window.open ("http://www.docjs.com/tips/tips/", "tips"); here, we assigned to a new window to 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: You can also change the URL: RecentTips.Location.href = "http: // www by the following method. Usatoday.com/ "; In the front section, you have seen how to open a new window using the HTML link and form. 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 you perform the following statement, you get a reference to a new window: VAR LatestNews = Window.Open ("" "," news "); let us try again. Click this link to CNET, but it is loaded, click the button below: This button actually retrieves the reference to the name "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: