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

Use javascript to always keep the same child window open and close the parent window while automatically closing all child windows_javascript skills

WBOY
Release: 2016-05-16 19:12:51
Original
1009 people have browsed it

I saw this article on the Internet today, and I feel that it is rarely used, but after all, some people still need such a function, otherwise there would be no such article. This article mainly solves the following problems:

Copy code The code is as follows:

1. Click a link that can open a new form. How to implement the if form If it is open, the focus goes to the already opened form, otherwise it opens a new form. Difficulty: How to determine whether the form is open and whether the form to be opened is Active?
2. How to close all other related open forms when a main form is closed?
Implementation points:
1. window.open will return the window object of the newly opened window.
2. Implement a simulated simple HashMap to store the window object of the child window.
3. Each time it is opened, retrieve this HashMap to determine whether the child window already exists.
4. If it exists, switch the focus directly (window.focus).
5. If it does not exist, open one.
6. For 4, it is possible that the sub-window has been closed, so I took some tricks and first called its focus (in fact, it can be any method). If there is an error, open one as well.
7. When closing the parent, traverse the HashMap and try to close all child windows.
8. All operations are performed in the parent window.
9. The whole implementation principle is actually very simple, as long as you need to be familiar with js and dhtml, and then pay attention to the details.

Currently, IE 6 sp1 has passed the test. FF is not suitable for use because it does not support window.focus.

[Ctrl A Select all Note:
If you need to introduce external Js, you need to refresh to execute
] Package file download
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template