• 原生JS ajax 判定浏览器是否关闭


        <script language="javascript" type="text/javascript">
          //这个函数是一直固定不变的,你只需要调用它,检验是否能创建 XMLHttpRequest对象
          var xmlHttp;  
          function createXmlHttpRequest() {     
            if (window.XMLHttpRequest) {
              xmlHttp = new XMLHttpRequest();

              if (xmlHttp.overrideMimeType) {
                xmlHttp.overrideMimeType("text/xml");
              }
            }
            else if (window.ActiveXObject) {
              try {
                alert("测试成功");
                xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
              }
              catch (e) {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
              }
            }
            if (!xmlHttp) {
              window.alert("你的浏览器不支持创建XMLhttpRequest对象 \n- 请换用IE 或 火狐");
            }
            return xmlHttp;
          }
          function ChangeSessionID()
          {
            var id = '<%=Session["UserID"] %>';
         
            if (!createXmlHttpRequest())
            {
              alert('程序执行出现错误。');
            }
            else
            {
              var xmlHttpTest = createXmlHttpRequest();
              var url = "Handler1.ashx?value=" + id;
              xmlHttpTest.open("get", url, true);
              xmlHttpTest.send(null);
             }
          }
          function close() {
            if (document.body.clientWidth - event.clientX < 170 && event.clientY < 0 || event.altKey) {
              ChangeSessionID();
            }
          }
          window.onbeforeunload = close;
        </script>

  • 相关阅读:
    Vim配置
    9.24CSPS模拟10
    10.3CSPS模拟16
    9.26CSPS模拟12
    我被机惨了
    9.25模拟赛
    多层项目中使用EFCore
    EFCore 执行原生SQL语句
    批处理 压缩日志,删除历史文件
    EF的全局过滤器 HasQueryFilter 从EFCore 2.0才有
  • 原文地址:https://www.cnblogs.com/xiaozhuaweiliang/p/ajax.html
Copyright © 2020-2023  润新知