JavaScript Window Function Guide Check if a window exists

zhaozj2021-02-08  201

Check the window a JavaScript window function of whether there is a guide (Author: hear the wind compiler 2001 at 11:35 on January 19) When you create a new window to open () method returns the value assigned to a variable is very important. For example, the following statement creates a new window, then close it immediately: win = window.open ("http://www.docjs.com/", "js"); win.close (); Window object every browse Both the window correspond to a clear 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 (). When you want to manipulate a window, you must confirm that it exists. When a variable is defined for the Window.open () method, it is defined as global variables and set to NULL. Remember, the Open () method returns the Window object of the new window. Here is an example: VAR WIN = NULL; function launchWindow () {win = window.Open (); // statements That Refer to the new window Go Here} If you want to perform an action on the new window, you should first check the variable WIN is NULL: // if Win EXISTS, MOVE THE WINDOW IF WIN.MOVETO (0, 0); Note, NULL is equal to FALSE, and any other legal object is equivalent to TRUE. If Win is equal to TRUE, you know it is not null, which means that the new window is successfully created. Open "Properties" Now you know the browser actually created a new window. But is it still existing? It is not necessary. You need to confirm that the available window does have a real Window object. Since each Window object corresponds to an Open () method, you can check this method through object probing: // If Win.Open exists, mobile window IF (win.open) win.moveto (0, 0); Variable WIN control window's Window object, so Win.Open corresponds to the Window.Open method of Window. Note that the conditional expression is a function reference, not a function call. Unless you confirm that Win exists, you should not try to estimate Win.Open. The following statement describes the correct implementation: // if Win and win.open exist, move the window if (win && win.open) win.moveto (0, 0); because && is a short operation symbol, if A parameter (win) corresponds to true, then the result depends on the second value.

转载请注明原文地址:https://www.9cbs.com/read-3458.html

New Post(0)