In my chat application,I need an confirmation box to logout when closing the window.
Ok button in confirmation box works fine.but,
If i press, cancel in the confirmation box,I dont need to close the browser window..
In my case if i press cancel ,My browser window was closed...Please help me...
window.onunload = function () {
var confirmation = confirm("Are you Sur want to logout the session ?");
if (confirmation == true)
{
if((sessionId != null)&&(sessionId!="null")&& (sessionId != ""))
logout();
// confirmation = "You pressed OK!";
}
else
{
// confirmation = "You pressed Cancel!";
}
};
In logout code,
function logout(){
//alert("<---------->"+userId+";"+secureKey+";"+name);
clearInterval(timer);
document.getElementById("button3").style.display = "none";
document.getElementById("message").innerText = "";
try
{
xmlhttp.onreadystatechange=function()
{
//alert("Status : "+xmlhttp.status+"\nreadyState : "+xmlhttp.readyState);
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
//alert("<---------->"+userId+";"+secureKey+";"+name);
//alert(xmlhttp.responseText.toString());
}
};
xmlhttp.open("POST","LogoutAction?&userId="+userId+"&secureKey="+secureKey+"&nickname="+name,true);
xmlhttp.send();
}
catch(err)
{
alert(err.description);
}
}
In LogoutAction Servlet,
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
secureKey = request.getParameter("secureKey");
userId = request.getParameter("userId");
//nickname = request.getParameter(nickname);
protocol = ApplicationInfo.flexProtocol;
logout = new Logout();
logout.requestLogout(secureKey, userId, null, protocol);
//out.println(secureKey+";"+userId+";"+nickname);
}
In java code,
public class Logout {
public void requestLogout(String secureKey, String userId, String nickname, FlexChatProtocol protocol) {
RequestLogout logout = null;
Message resp = null;
logout = RequestLogout.create();
logout.setSecureKey(secureKey);
logout.setUserId(userId);
try {
resp = protocol.request(logout);
System.out.println(resp);
} catch (ProtocolException e) {
} catch (IllegalStateException e) {
}
}
}
Thanks in advance..