7956505d by 任超

style:监听浏览器关闭

1 parent b57d0c0a
......@@ -20,9 +20,6 @@ function login() {
});
})
}
window.onbeforeunload = function () {
delCookie();
}
$(document).on('click', '.PersonLogin', function () {
login();
})
......@@ -42,16 +39,16 @@ $(document).on('click', '#loginButton', function () {
$(document).on('click', '#cancellation', function () {
layui.use('layer', function () {
layer.confirm('此操作将进行注销', {
btn: ['是','否'] //按钮
}, function(){
btn: ['是', '否'] //按钮
}, function () {
delCookie();
window.open('' + localhostPaht + '/index.html', '_self')
}, function(){
}, function () {
layer.msg('已取消');
});
})
});
function delCookie () {
function delCookie() {
var keys = document.cookie.match(/[^ =;]+(?==)/g)
if (keys) {
for (var i = keys.length; i--;) {
......@@ -68,10 +65,25 @@ $(function () {
if (getCookie('myCookie').username) {
$('.personalCenter').addClass('show');
}
var _beforeUnload_time = 0, _gap_time = 0;
var is_fireFox = navigator.userAgent.indexOf("Firefox") > -1;//是否是火狐浏览器
window.onunload = function () {
_gap_time = new Date().getTime() - _beforeUnload_time;
if (_gap_time <= 5) {
delCookie();
} else {//浏览器刷新
}
}
window.onbeforeunload = function () {
_beforeUnload_time = new Date().getTime();
if (is_fireFox) {//火狐关闭执行
delCookie();
}
};
})
// 点击注册的时候
$(document).on('click', '#registerButton', function () {
window.open(''+localhostPaht+'/staticViews/register.html', '_self')
window.open('' + localhostPaht + '/staticViews/register.html', '_self')
});
function clicklogin(data) {
$.ajax({
......@@ -84,7 +96,7 @@ function clicklogin(data) {
data: JSON.stringify(data),//***关键******
success: function (result) {//返回数据根据结果进行相应的处理
if (result.code == 200 && result.data !== null) {
setCookie('myCookie',result.data,60);
setCookie('myCookie', result.data, 60);
$('.personalCenter').addClass('show');
$('.PersonLogin').html(getCookie('myCookie').username);
layer.closeAll();
......