onunload   +  ajax

解决方案 »

  1.   

    我觉得应该在onbeforeunload事件中获取时间,ajax传递到后台进行处理!
      

  2.   

    test.html<html> 
    <head> 
    <title>AjaxTest </title> 
    <script> 
    var xmlHttp; 
    function createXMLHttpRequest() 

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

    function startRequest() 

        createXMLHttpRequest(); 
        xmlHttp.open("GET", "do.asp", true); 
        xmlHttp.send(null); } window.onunload = startRequest;</script> 
    </head> 
    <body> </body> 
    </html> 
    do.asp<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
    <!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>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <%
    Public Function CreatedTextFile(fromPath,body)
            On Error Resume Next
            Dim fso,fff
            If InStr(fromPath, ":") = 0 Then fromPath = Server.MapPath(fromPath)
            Set fso = Server.CreateObject("Scripting.FileSystemObject")
            Set fff = fso.OpenTextFile(fromPath, 2, True)
            fff.Write body
            fff.Close
            Set fff = Nothing
            Set fso = Nothing
            If Err.Number <> 0 Then Err.Clear
    End FunctionCreatedTextFile "test.txt",now()
    %>
    </head><body>
    </body>
    </html>