When the browser is closed (the browser program is closed and the browser tag is closed), some information is sent back to the server asynchronously.
HTML code
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Title> HTMLPage3 </title>
<Script language = "javascript" type = "text/javascript">
Var xmlHttp; www.2cto.com
Function createHttpRequest ()
{
If (! Window. XMLHttpRequest)
{
Window. XMLHttpRequest = function ()
{
Var progIDs = ['msxml2. XMLHTTP.4.0 ', 'msxml2. XMLHTTP.3.0', 'msxml2. XMLHTTP.2.6 ',
'Msxml2. xmlhttp', 'Microsoft. xmlhttp', 'msxml. xmlhttp'];
For (var I = 0; I <progIDs. length; I ++)
{
Try
{
XmlHttp = new ActiveXObject (progIDs [I]);
Break;
}
Catch (ex ){}
}
}
}
Else
{
XmlHttp = new XMLHttpRequest ();
}
}
Function doSearch ()
{
CreateHttpRequest ();
Var url = "myPage. aspx? Id ="
If (document. getElementById ("txt ")! = Null)
{
Url = url + escape (document. getElementById ("txt"). value)
}
Else
{
Url = url + "-1 ";
}
If (xmlHttp! = Null)
{
XmlHttp. open ("GET", url, true );
XmlHttp. send (null );
// Alert ("Send Complete! ");
}
}
Window. onbeforeunload = function ()
{
DoSearch ();
}
</Script>
</Head>
<Body>
<H1> HTMLPage3 <Input type = "text" id = "txt"/>
<Input type = "button" id = "btn" value = "Click" onclick = "doSearch ();"/>
</Body>
</Html>