DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> AJAX入門 >> AJAX詳解 >> 捕捉網頁的windowClose事件,並調用注銷登陸頁面
捕捉網頁的windowClose事件,並調用注銷登陸頁面
編輯:AJAX詳解     

<Html>
<head>
<title> New Document </title>
</head>

<script language="JavaScript">


function getUrl(url)
{
 var result = null;
 var request = false;

 if (window.XMLHttpRequest)
 {
    request = new XMLHttpRequest();
 }
 else if (window.ActiveXObject)
 {
    request = new ActiveXObject("Microsoft.XMLHTTP");
 }


 if (!request)
   alert("Error initializing XMLHttpRequest!");
 else
 {
  request.open("GET", url, false);
  request.send(null);
  result = request.responseText;
 }
 request = null;
 return result;
}

function onWindowClose()
{
 //var url = "http://www.google.com/"; // for local file
 //var url = "/logout.ASP";
 var url = "/";
 var s = getUrl(url);
 alert(s);
}

function mouseIsInXButton()
{
 return (event.clientY < 0)  &&  ((document.body.offsetWidth - event.clIEntX) < 30);
}

</script>

<script language="JavaScript" FOR=window EVENT=onbeforeunload>

 // x button / alt+f4 / ctrl + f4
 if( mouseIsInXButton() || event.altKey || event.ctlKey)
 {
  onWindowClose(); 
 }
</script>


<body>
 Clear session on window close
</body>
</Html>

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved