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:
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.
If you need to introduce external Js, you need to refresh to execute
]
Package file download