Recently, a privilege management system was encountered. Because the system of rights management and the original system style is inconsistent, all new open a window. The problem is, admin logout, the Rights Management window is not closed. After other normal users log on, they can still manipulate the Rights Management window.
Problem simplification: When admin logs off, or when main.html closes, all new windows that are open are closed together. The problem is solved.
Just look at the code:
Copy Code code as follows:
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<title>insert title here</title>
<body onunload= "closenews ();" >
<a href= "#" onclick= "opennew (' http://www.baidu.com ', ' Nihao ')" > Open new Window </a>
<a href= "#" onclick= "LogOut ();" > Exit Login </a>
</body>
<script>
The user records all open child windows
var win_array = new Array ();
var win_num =-1;
Every time you open a new window, it's recorded.
function Opennew (uri,param) {
Win_num = win_num+1;
Win_array[win_num] = window.open (URI);
}
When the user logs off, the Shutdown method is performed. Body Add onunload = "closenews ();" When main window closes, all child windows are closed
function Closenews () {
Turn off Rights Management
if (Win_array.length > 0) {
for (var i = 0;i <= win_array.length;i++) {
var win_one = win_array[i];
if (win_one!= undefined) {
Win_one.close ();
}
}
}
}
function LogOut () {
Close child windows
Closenews ();
Exit Login
}
</script>
Explain:
<body onunload= "closenews ();" > Adding onunload events to the body is important. That is, when the window closes, execute the method of closing all child windows.
Test: In the Web project, Ie8,ie10, Firefox, Chrome,opera are all fine.
Once the Wen container is not put down, just static main.html page, IE has a problem, because the static, ie window.open () is actually open a new page, not open a new label. All methods that close the window are no longer valid.
Time is limited, has not spent energy to examine, but also hope to know why the JS technology can guide the big God. Thanks again.