style:监听浏览器关闭
Showing
1 changed file
with
21 additions
and
9 deletions
| ... | @@ -20,9 +20,6 @@ function login() { | ... | @@ -20,9 +20,6 @@ function login() { |
| 20 | }); | 20 | }); |
| 21 | }) | 21 | }) |
| 22 | } | 22 | } |
| 23 | window.onbeforeunload = function () { | ||
| 24 | delCookie(); | ||
| 25 | } | ||
| 26 | $(document).on('click', '.PersonLogin', function () { | 23 | $(document).on('click', '.PersonLogin', function () { |
| 27 | login(); | 24 | login(); |
| 28 | }) | 25 | }) |
| ... | @@ -42,16 +39,16 @@ $(document).on('click', '#loginButton', function () { | ... | @@ -42,16 +39,16 @@ $(document).on('click', '#loginButton', function () { |
| 42 | $(document).on('click', '#cancellation', function () { | 39 | $(document).on('click', '#cancellation', function () { |
| 43 | layui.use('layer', function () { | 40 | layui.use('layer', function () { |
| 44 | layer.confirm('此操作将进行注销', { | 41 | layer.confirm('此操作将进行注销', { |
| 45 | btn: ['是','否'] //按钮 | 42 | btn: ['是', '否'] //按钮 |
| 46 | }, function(){ | 43 | }, function () { |
| 47 | delCookie(); | 44 | delCookie(); |
| 48 | window.open('' + localhostPaht + '/index.html', '_self') | 45 | window.open('' + localhostPaht + '/index.html', '_self') |
| 49 | }, function(){ | 46 | }, function () { |
| 50 | layer.msg('已取消'); | 47 | layer.msg('已取消'); |
| 51 | }); | 48 | }); |
| 52 | }) | 49 | }) |
| 53 | }); | 50 | }); |
| 54 | function delCookie () { | 51 | function delCookie() { |
| 55 | var keys = document.cookie.match(/[^ =;]+(?==)/g) | 52 | var keys = document.cookie.match(/[^ =;]+(?==)/g) |
| 56 | if (keys) { | 53 | if (keys) { |
| 57 | for (var i = keys.length; i--;) { | 54 | for (var i = keys.length; i--;) { |
| ... | @@ -68,10 +65,25 @@ $(function () { | ... | @@ -68,10 +65,25 @@ $(function () { |
| 68 | if (getCookie('myCookie').username) { | 65 | if (getCookie('myCookie').username) { |
| 69 | $('.personalCenter').addClass('show'); | 66 | $('.personalCenter').addClass('show'); |
| 70 | } | 67 | } |
| 68 | var _beforeUnload_time = 0, _gap_time = 0; | ||
| 69 | var is_fireFox = navigator.userAgent.indexOf("Firefox") > -1;//是否是火狐浏览器 | ||
| 70 | window.onunload = function () { | ||
| 71 | _gap_time = new Date().getTime() - _beforeUnload_time; | ||
| 72 | if (_gap_time <= 5) { | ||
| 73 | delCookie(); | ||
| 74 | } else {//浏览器刷新 | ||
| 75 | } | ||
| 76 | } | ||
| 77 | window.onbeforeunload = function () { | ||
| 78 | _beforeUnload_time = new Date().getTime(); | ||
| 79 | if (is_fireFox) {//火狐关闭执行 | ||
| 80 | delCookie(); | ||
| 81 | } | ||
| 82 | }; | ||
| 71 | }) | 83 | }) |
| 72 | // 点击注册的时候 | 84 | // 点击注册的时候 |
| 73 | $(document).on('click', '#registerButton', function () { | 85 | $(document).on('click', '#registerButton', function () { |
| 74 | window.open(''+localhostPaht+'/staticViews/register.html', '_self') | 86 | window.open('' + localhostPaht + '/staticViews/register.html', '_self') |
| 75 | }); | 87 | }); |
| 76 | function clicklogin(data) { | 88 | function clicklogin(data) { |
| 77 | $.ajax({ | 89 | $.ajax({ |
| ... | @@ -84,7 +96,7 @@ function clicklogin(data) { | ... | @@ -84,7 +96,7 @@ function clicklogin(data) { |
| 84 | data: JSON.stringify(data),//***关键****** | 96 | data: JSON.stringify(data),//***关键****** |
| 85 | success: function (result) {//返回数据根据结果进行相应的处理 | 97 | success: function (result) {//返回数据根据结果进行相应的处理 |
| 86 | if (result.code == 200 && result.data !== null) { | 98 | if (result.code == 200 && result.data !== null) { |
| 87 | setCookie('myCookie',result.data,60); | 99 | setCookie('myCookie', result.data, 60); |
| 88 | $('.personalCenter').addClass('show'); | 100 | $('.personalCenter').addClass('show'); |
| 89 | $('.PersonLogin').html(getCookie('myCookie').username); | 101 | $('.PersonLogin').html(getCookie('myCookie').username); |
| 90 | layer.closeAll(); | 102 | layer.closeAll(); | ... | ... |
-
Please register or sign in to post a comment