日期:2014-05-18  浏览次数:20634 次

点击关闭按钮执行一串代码问题
我希望在只在关闭该页面的时候执行function       window.onunload(),为什么在刚打开这个页面时也执行function       window.onunload()   ?
该页面代码如下:

<HTML>
<HEAD>
<%@   page  
language= "java "
contentType= "text/html;   charset=GBK "
pageEncoding= "GBK "
%>
<META   http-equiv= "Content-Type "   content= "text/html;   charset=GBK ">

<title> 聊天室 </title>
<%@   page   import   =   "StudyBbs.* "   %>
<%@   page   import   =   "java.util.* "   %>

<%


String   Name   =(String)   session.getAttribute( "username ");
%>
<script       language= "javascript ">      
    function       window.onunload()      
    {      
        <%
     
      String   Name1   =(String)   session.getAttribute( "username ");
Vector   ListUser=null;
        ListUser   =(Vector)application.getAttribute( "UserName ");
        ListUser.remove(Name1);
        out.print( "alert(\ "您已退出聊天室!\ "); ");
        System.out.println( "error ");
%>
    }      
    </script>
</head>
<frameset   rows   =   "*,100 "           >
<frameset   cols   =   "*,150 "   >
  <frame   src   =   "show.jsp "   name= "mainFrame "   scrolling= "auto ">
<frameset   rows   =   "80,*,0 "   >
<frame   name   =   "image "   src= "image.htm ">
<frame   name   =   "userlistFrame "   src= "userlist.jsp ">
<frame   name   =   "hiddenFrame "   src= "transact.jsp ">
</frameset>
</frameset>
    <frame   src= "input.jsp?username= <%=   Name   %> "   name= "inputFrame ">
</frameset>
<noframes>
<body   bgcolor= "#FFFFFF "   >
您的浏览器不支持框架,对不起!
</body   >

</noframes>
</html>




------解决方案--------------------
http://bbs.51js.com/viewthread.php?tid=67863