search
HomeWeb Front-endJS TutorialJavaScript pop-up window window.open usage method and parameter description analysis_Basic knowledge

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、内包含的弹出窗口-一个页面两个窗口】
上面的例子都包含两个窗口,一个是主窗口,另一个是弹出的小窗口。
通过下面的例子,你可以在一个页面内完成上面的效果。

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

看看 OpenWindow.document.write()里面的代码不就是标准的HTML吗?只要按照格式写更多的行即可。千万注意多一个标签或少一个标签就会出现错误。记得用OpenWindow.document.close()结束啊。
【9、终极应用--弹出的窗口之Cookie控制】
回想一下,上面的弹出窗口虽然酷,但是有一点小毛病(沉浸在喜悦之中,一定没有发现吧?)比如你将上面的脚本放在一个需要频繁经过的页面里(例如首页),那么每次刷新这个页面,窗口都会弹出一次,是不是非常烦人?:-( 有解决的办法吗?Yes! ;-) Follow me.
我们使用cookie来控制一下就可以了。
首先,将如下代码加入主页面HTML的区:

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

然后,用(注意不是openwin而是loadpop啊!)
替换主页面中原有的这一句即可。你可以试着刷新一下这个页面或重新进
入该页面,窗口再也不会弹出了。真正的Pop-Only-Once!
写到这里弹出窗口的制作和应用技巧基本上算是完成了
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
Python vs. JavaScript: A Comparative Analysis for DevelopersPython vs. JavaScript: A Comparative Analysis for DevelopersMay 09, 2025 am 12:22 AM

The main difference between Python and JavaScript is the type system and application scenarios. 1. Python uses dynamic types, suitable for scientific computing and data analysis. 2. JavaScript adopts weak types and is widely used in front-end and full-stack development. The two have their own advantages in asynchronous programming and performance optimization, and should be decided according to project requirements when choosing.

Python vs. JavaScript: Choosing the Right Tool for the JobPython vs. JavaScript: Choosing the Right Tool for the JobMay 08, 2025 am 12:10 AM

Whether to choose Python or JavaScript depends on the project type: 1) Choose Python for data science and automation tasks; 2) Choose JavaScript for front-end and full-stack development. Python is favored for its powerful library in data processing and automation, while JavaScript is indispensable for its advantages in web interaction and full-stack development.

Python and JavaScript: Understanding the Strengths of EachPython and JavaScript: Understanding the Strengths of EachMay 06, 2025 am 12:15 AM

Python and JavaScript each have their own advantages, and the choice depends on project needs and personal preferences. 1. Python is easy to learn, with concise syntax, suitable for data science and back-end development, but has a slow execution speed. 2. JavaScript is everywhere in front-end development and has strong asynchronous programming capabilities. Node.js makes it suitable for full-stack development, but the syntax may be complex and error-prone.

JavaScript's Core: Is It Built on C or C  ?JavaScript's Core: Is It Built on C or C ?May 05, 2025 am 12:07 AM

JavaScriptisnotbuiltonCorC ;it'saninterpretedlanguagethatrunsonenginesoftenwritteninC .1)JavaScriptwasdesignedasalightweight,interpretedlanguageforwebbrowsers.2)EnginesevolvedfromsimpleinterpreterstoJITcompilers,typicallyinC ,improvingperformance.

JavaScript Applications: From Front-End to Back-EndJavaScript Applications: From Front-End to Back-EndMay 04, 2025 am 12:12 AM

JavaScript can be used for front-end and back-end development. The front-end enhances the user experience through DOM operations, and the back-end handles server tasks through Node.js. 1. Front-end example: Change the content of the web page text. 2. Backend example: Create a Node.js server.

Python vs. JavaScript: Which Language Should You Learn?Python vs. JavaScript: Which Language Should You Learn?May 03, 2025 am 12:10 AM

Choosing Python or JavaScript should be based on career development, learning curve and ecosystem: 1) Career development: Python is suitable for data science and back-end development, while JavaScript is suitable for front-end and full-stack development. 2) Learning curve: Python syntax is concise and suitable for beginners; JavaScript syntax is flexible. 3) Ecosystem: Python has rich scientific computing libraries, and JavaScript has a powerful front-end framework.

JavaScript Frameworks: Powering Modern Web DevelopmentJavaScript Frameworks: Powering Modern Web DevelopmentMay 02, 2025 am 12:04 AM

The power of the JavaScript framework lies in simplifying development, improving user experience and application performance. When choosing a framework, consider: 1. Project size and complexity, 2. Team experience, 3. Ecosystem and community support.

The Relationship Between JavaScript, C  , and BrowsersThe Relationship Between JavaScript, C , and BrowsersMay 01, 2025 am 12:06 AM

Introduction I know you may find it strange, what exactly does JavaScript, C and browser have to do? They seem to be unrelated, but in fact, they play a very important role in modern web development. Today we will discuss the close connection between these three. Through this article, you will learn how JavaScript runs in the browser, the role of C in the browser engine, and how they work together to drive rendering and interaction of web pages. We all know the relationship between JavaScript and browser. JavaScript is the core language of front-end development. It runs directly in the browser, making web pages vivid and interesting. Have you ever wondered why JavaScr

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor