zoukankan      html  css  js  c++  java
  • Jquery detect page refresh

    first thing there are 3 functions we will use:

    function setCookie(c_name, value, exdays) {
                var exdate = new Date();
                exdate.setDate(exdate.getDate() + exdays);
                var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
                document.cookie = c_name + "=" + c_value;
            }
      
        function getCookie(c_name) {
            var i, x, y, ARRcookies = document.cookie.split(";");
            for (i = 0; i < ARRcookies.length; i++) {
                x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
                y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
                x = x.replace(/^s+|s+$/g, "");
                if (x == c_name) {
                    return unescape(y);
                }
            }
        }
      
        function DeleteCookie(name) {
                document.cookie = name + '=; expires=Thu, 01-Jan-70 00:00:01 GMT;';
            }
    

      Now we will start with the page load:

    $(window).load(function () {
     //if IsRefresh cookie exists
     var IsRefresh = getCookie("IsRefresh");
     if (IsRefresh != null && IsRefresh != "") {
        //cookie exists then you refreshed this page(F5, reload button or right click and reload)
        //SOME CODE
        DeleteCookie("IsRefresh");
     }
     else {
        //cookie doesnt exists then you landed on this page
        //SOME CODE
        setCookie("IsRefresh", "true", 1);
     }
    })
    

      

  • 相关阅读:
    缓存与清除缓存
    PHP文件缓存与memcached缓存 相比 优缺点是什么呢
    memcached的基本命令(安装、卸载、启动、配置相关)
    54点提高PHP编程效率 引入缓存机制提升性能
    登陆类
    格式化金额数与自动四舍五入
    如何用Ajax传一个数组数据
    CodeIgniter的缓存机制与使用方法
    CI框架缓存的实现原理
    PHP导出数据库方法
  • 原文地址:https://www.cnblogs.com/toSeeMyDream/p/4096619.html
Copyright © 2011-2022 走看看