Recently, I encountered a permission management system. Since the permission management system is inconsistent with the original system style, a new window will be opened. The problem arises. After the admin logs out, the permission management window is not closed. After other ordinary users log in, they can still operate the permission management window.
Simplified problem: When the admin logs out, or when main.html is closed, all new windows that are opened are closed together. The problem is solved
Just look at the code:
< html>
Insert title here< /title>
Open new window Log out <script> <br>//User records all open child windows<br>var win_Array = new Array(); <br>var win_num = -1; <br><br>//Record every time a new window is opened <br>function openNew(uri,param){ <br>win_num = win_num 1; <br>win_Array[ win_num] = window.open(uri); <br>} <br><br>//When the user logs out, execute the shutdown method. Body adds onUnload = "closeNews();" When the main window is closed, all child windows are closed <br>function closeNews(){ <br>//Close permission management <br>if(win_Array.length > 0){ <br>for(var i = 0;i <= win_Array.length;i ){ <BR>var win_one = win_Array[i]; <BR>if(win_one != undefined){ <BR>win_one.close( ); <BR>} <BR>} <BR>} <BR>} <br><br>function logOut(){ <BR>//Close the child window <BR>closeNews(); <br><br> //Log out<BR>} <br><br></script>
Explain:
It is important to add the onUnload event on the body. That is: when the window is closed, execute the method of closing all child windows.
Test: In the web project, there is no problem with ie8, ie10, Firefox, chrome, and opera.
Once the main.html page is not placed in the wen container but is static, IE has a problem, because when it is static, IE's window.open() actually opens a new page, not a new tab. . All methods of closing the window no longer work.
Time is limited and I haven’t spent the energy to study it in detail. I hope a js technology expert who knows why can give some guidance. Thanks again.