session ne venant à échéance après la fenêtre du navigateur Close- Javascript
<script>
\t \t function ServerPing(){
var url = "http://localhost:8080/index.html";
if (window.XMLHttpRequest){
reqXML = new XMLHttpRequest();
reqXML.onreadystatechange = HandlePing;
reqXML.open("GET", url, true);
reqXML.send(null);
}
else if(window.ActiveXObject){
reqXML = new ActiveXObject("Microsoft.XMLHTTP");
if(reqXML){
reqXML.onreadystatechange = HandlePing;
reqXML.open("GET", url, true);
reqXML.send(null);
}
}
else{
window.location.href = url;
}
}
function HandlePing(){
window.status = "Pinging Server - state: " + reqXML.readyState;
if(reqXML.readyState == 4){
var strDate = new Date().toString();
if(reqXML.status == 200){
window.status = "Sucessfull Ping at " + strDate;
}
else{
window.status = "Failed Ping at " + strDate;
}
}
}
window.onload = function(){
var timer = setInterval("ServerPing()",10000)
}
\t \t
\t \t </script>
<HTML>
<HEAD>
<TITLE> Test</TITLE>
\t
\t \t <script>
\t \t function ServerPing(){
var url = "http://localhost:8383/fcpbweb/index.html";
if (window.XMLHttpRequest){
reqXML = new XMLHttpRequest();
reqXML.onreadystatechange = HandlePing;
reqXML.open("GET", url, true);
reqXML.send(null);
}
else if(window.ActiveXObject){
reqXML = new ActiveXObject("Microsoft.XMLHTTP");
if(reqXML){
reqXML.onreadystatechange = HandlePing;
reqXML.open("GET", url, true);
reqXML.send(null);
}
}
else{
window.location.href = url;
}
}
function HandlePing(){
window.status = "Pinging Server - state: " + reqXML.readyState;
if(reqXML.readyState == 4){
var strDate = new Date().toString();
if(reqXML.status == 200){
window.status = "Sucessfull Ping at " + strDate;
}
else{
window.status = "Failed Ping at " + strDate;
}
}
}
window.onload = function(){
var timer = setInterval("ServerPing()",10000)
}
\t \t
\t \t </script>
</HEAD>
<BODY>
\t \t <div style="height:300px; width:400px; overflow:hidden; border:1px solid red;">
\t \t
\t \t
\t \t <p style="margin:117px auto 0 auto; width:150px">TEST CONTENT</p>
\t \t
\t \t </div>
</BODY>
</HTML>
Quand je fermer mon onglet du navigateur ma session ne s'expire dans IE8, Chrome & firefox.It fonctionne très bien dans IE9. Ma principale est JSP.
HTML:
<body onbeforeunload="HandleOnClose()"></body>
Code JS:
function HandleOnClose(){
if (event.clientY < 0) {
//event.returnValue = 'Want to leave the page?';
location.href=location.protocol+"//"+location.host+"${ctx}/"+logoutLocation;
}
}
J'ai refered lien ci-dessous aussi, mais pas travaillé.
window.onunload is not working properly in Chrome browser. Can any one help me?
Je suis également en utilisant le framework Prototypejs. Je suis ouvert à d'autres solutions également.
Merci d'avance.
Crowder: Comment faire un ping server.I ne comprenait pas. Connaissez-vous un exemple ou un blog.Je cherche réponse dans JS seulement.Thnx –
Je suis ouvert à toutes les solution possible/option. –
@MikePhils: Vous pinguez le serveur en utilisant "ajax" (['XMLHttpRequest'] (https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest)). –