Home >Web Front-end >JS Tutorial >JavaScript pop-up window window.open usage method and parameter description analysis_Basic knowledge

JavaScript pop-up window window.open usage method and parameter description analysis_Basic knowledge

WBOY
WBOYOriginal
2016-05-16 18:39:581727browse
window.open usage and parameter description
1. window.open() supported environment:  
 JavaScript1.0 /JScript1.0 /Nav2 /IE3 /Opera3
 
2 , Basic syntax:
 
 window.open(pageURL,name,parameters)
 
 Among them:
 pageURL is the sub-window path
 name is the sub-window handle
 parameters is the window Parameters (each parameter is separated by commas)
 
3. Parameters
 
Where yes/no can also use 1/0; pixel value is a specific value, in pixels.
 
 Parameter | Value range| Description| |
 alwaysLowered | yes/no | The specified window is hidden behind all windows
> Depended | yes/no | Whether to close at the same time as the parent window
Directories | yes/no | Whether the directory bar of Nav2 and 3 is visible
Height | pixel value | Window height
hotkeys | yes/no | in A safe exit hotkey is set in a window without a menu bar
innerHeight | pixel value | pixel height of the document in the window
innerWidth | pixel value | pixel width of the document in the window
location | yes/no | location bar Is it visible?
Menubar | yes/no | Is the menu bar visible?
OuterHeight | pixel value | Set the pixel height of the window (including decorative borders) pixel width of the decorative border
resizable | yes/no | whether the window size can be adjusted
screenX | pixel value | pixel length of the window from the left border of the screen
screenY | pixel value | Pixel length
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 | pixel width of the window
z-look | yes/no | whether the window floats on top of other windows after it is activated
Let me take you to analyze its mystery.
[1. The most basic pop-up window code]
In fact, the code is very simple:




[Ctrl A Select all Note: If you need to introduce external Js, you need to refresh to execute it ] Because it is a piece of javascripts code , so 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 written in front, the absolute path (http Both ://) and relative paths (..
/) are acceptable.
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.



[Ctrl A select all Note: If you need to introduce external Js, you need to refresh to execute ]
参数解释:
js脚本结束
【3、用函数控制弹出窗口】
下面是一个完整的代码。

[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]

这里定义了一个函数openwin(),函数内容就是打开一个窗口。在调用它之前没有任何用途。
怎么调用呢?
方法一: 浏览器读页面时弹出窗口;
方法二: 浏览器离开页面时弹出窗口;
方法三:用一个连接调用:
打开一个窗口
注意:使用的“#”是虚连接。
方法四:用一个按钮调用:

【4、同时弹出2个窗口】
对源代码稍微改动一下:

[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]

为避免弹出的2个窗口覆盖,用top和left控制一下弹出的位置不要相互覆盖即可
。最后用上面说过的四种方法调用即可。
注意:2个窗口的name(newwindows和newwindow2)不要相同,或者干脆全部为空。
OK?
【5、主窗口打开文件1.htm,同时弹出小窗口page.html】
如下代码加入主窗口区:

加入区:
open即可。
【6、弹出的窗口之定时关闭控制】
下面我们再对弹出的窗口进行一些控制,效果就更好了。如果我们再将一小段代码加入弹出的页面(注意是加入到page.html的HTML中,可不是主页面中,否则...),让它10秒后自动关闭是不是更酷了?
首先,将如下代码加入page.html文件的区:

然后,再用 这一句话代替page.html中原有的DY>这一句就可以了。(这一句话千万不要忘记写啊!这一句的作用是调用关闭窗口的代码,10秒钟后就自行关闭该窗口。)
【7、在弹出窗口中加上一个关闭按钮】



呵呵,现在更加完美了!
【8、内包含的弹出窗口-一个页面两个窗口】
上面的例子都包含两个窗口,一个是主窗口,另一个是弹出的小窗口。
通过下面的例子,你可以在一个页面内完成上面的效果。
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn