Home > Web Front-end > JS Tutorial > body text

Detailed explanation of the use of window.open() method in js_Basic knowledge

WBOY
Release: 2016-05-16 17:27:52
Original
964 people have browsed it
1. Window.open() supported environment:
JavaScript1.0 /JScript1.0 /Nav2 /IE3 /Opera3

2. Basic syntax:
window.open(pageURL,name,parameters)
Where:
pageURL is the sub-window path
name is the sub-window handle
parameters is the window parameters (each parameter is separated by a comma)

3. Example:
Copy code The code is as follows:

<SCRIPT> <br><!-- <BR>window.open ('page.html','newwindow','height=100,width=400,top=0,left=0,toolbar=no ,menubar=no,scrollbars=no, resizable=no,location=no, status=no') <BR>//Write in one line<BR>--> <br></SCRIPT>

After the script is run, page.html will be opened in a new window with a width of 100, a height of 400, 0 pixels from the top of the screen, 0 pixels from the left of the screen, no toolbar, no menu bar, and no scrolling. Bar, not resizable, no address bar, no status bar. Please compare.
The above example involves several commonly used parameters. In addition, there are many other parameters, please see 4.

4. Various parameters
Among them yes/no can also use 1/0; pixel value is a specific value, unit pixel.

Parameter | Value range | Description

alwaysLowered | yes/no | The specified window is hidden behind all windows
alwaysRaised | yes/no | The specified window is suspended above all windows
depended | yes/no | Whether to close the parent window at the same time
directories | yes/no | whether the directory bar of Nav2 and 3 is visible
height | pixel value | window height
hotkeys | yes/no | Set the safe exit hotkey in a window without a menu bar
innerHeight | pixel value | The pixel height of the document in the window
innerWidth | pixel value | The pixel width of the document in the window
location | yes/no | location Is the bar visible? ) pixel width
resizable | yes/no | whether the window size is resizable
screen
scrollbars | yes/no | Whether the window can have a scroll bar
titlebar | yes/no | Whether the window title bar is visible
toolbar | yes/no | Whether the window toolbar is visible
Width | pixel value | The pixel width of the window
z-look | yes/no | Whether the window floats above other windows after it is activated

================== ====================================

【1. The most basic pop-up window Code]
Actually the code is very simple:




Copy code
The code is as follows: < SCRIPT LANGUAGE="javascript">



Because it is a piece of javascripts code, they should be placed between the . are effective for some older browsers. In these old browsers, the code in the tag will not be displayed as text. Develop this good habit.
Window.open ('page.html') is used to control the pop-up of a new window page.html. If page.html is not in the same path as the main window, the path should be stated in front, the absolute path (http:// ) and relative paths (../) are available. You can use either single quotes or double quotes, just don't mix them.
This piece of code can be added anywhere in the HTML, between and , and between . The earlier it is, the earlier it will be executed, especially if the page code is long. , and if you want the page to pop up earlier, put it as far forward as possible.

【2. Pop-up window after setting】

Let’s talk about the settings of pop-up window. Just add a little more to the code above.
Let’s customize the appearance, size, and pop-up position of this pop-up window to suit the specific conditions of the page.




Copy code
The code is as follows:


Parameter explanation:
js script ends

[3. Use functions to control pop-up windows]

The following is a complete code.
Copy code The code is as follows:





To avoid being covered by the two pop-up windows, Use top and left to control the pop-up position so that it does not cover each other. Finally, you can call it using the four methods mentioned above.
Note: The names of the two windows (newwindows and newwindow2) should not be the same, or they should all be empty. OK?

[5. The main window opens the file 1.htm, and the small window page.html pops up at the same time]

The following code is added to the main window area:
Copy code The code is as follows:

Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template