首页 > 代码库 > Jquery detect page refresh
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); }})
Jquery detect page refresh
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。