onbeforeunload

Detect browser close event

你说的曾经没有我的故事 提交于 2021-01-28 15:16:31
问题 I want to capture the browser window/tab close event. I have tried the following But not working: <script type="text/javascript"> window.onbeforeunload = function(){ myUnloadEvent(); } function myUnloadEvent() { alert ('Calling some alert messages here'); } </script> <body> Body of the page goes here. </body> Tried these links also but no more success. javascript to check when the browser window is close How to capture the browser window close event? javascript detect browser close tab/close

logout a meteor user on window/tab close but not on page refresh.

余生颓废 提交于 2021-01-28 07:40:35
问题 I have used window.onbeforeunload to logout a meteor user on browser tab close. It works fine with tab close but my user gets log out on page refresh which I do not want. Is there any solution to this problem. I want user to not logout on page refresh. I am new in Meteor. Any help would be highly appreciated. The code I have used for this is window.onbeforeunload = function() { Meteor.logout(); } 回答1: I'm kinda new to meteor too and after many tries I found this solution : if (sessionStorage

I need to capture the window.onbeforeunload event

无人久伴 提交于 2021-01-01 18:37:01
问题 I am working on a project where I need to capture the browser close event ( unload or beforeunload ). For that I have tried the code below but it's not working. The code is working only if I open the browser console window (maybe just for a second) but it is required otherwise it's not working. Example $(window).on('beforeunload', function(e) { $.ajax({ type: "POST", url: "url", data : {'value' : 1}, dataType:'json' }); return false; }); 回答1: The beacon API is meant specifically for that.

I need to capture the window.onbeforeunload event

帅比萌擦擦* 提交于 2021-01-01 18:36:13
问题 I am working on a project where I need to capture the browser close event ( unload or beforeunload ). For that I have tried the code below but it's not working. The code is working only if I open the browser console window (maybe just for a second) but it is required otherwise it's not working. Example $(window).on('beforeunload', function(e) { $.ajax({ type: "POST", url: "url", data : {'value' : 1}, dataType:'json' }); return false; }); 回答1: The beacon API is meant specifically for that.

Whats the point of `beforeunload` returnValue if the message does not get set?

谁说胖子不能爱 提交于 2020-08-10 05:00:19
问题 TL;DR No modern browsers use the message. You can abuse the api with this message so browsers dropped the use of the parameter. Thank you Huangism, lilezek, and James for the below responses. What is the point of setting the event returnValue in the onbeforeunload callback if the message never gets set? The MDN docs here recommend that we set this value, and I'm not able to prompt the user without setting this value. However when setting that value I don't see my string in any of the

wait for promises in onbeforeunload

半腔热情 提交于 2020-06-11 17:04:19
问题 I want to send a $http.get if the page gets closed. Then I stumbold upon a problem where promises can't get resolved because if this one last method returns, the page gets destroyed. The following does not work because onbeforeunload can't resolve promises / does not wait for them: window.onbeforeunload = function( $http.get('http://someth.ing/update-state?page=unloaded').then(function(){ // never called... never sent... } } I know, you can use default sync HTTP Methods but the question is

onBeforeUnload doesn't call methods, browser closes too fast?

我只是一个虾纸丫 提交于 2020-06-01 07:40:47
问题 I'm trying to call a method in the beforeunload event handler. It seems like the browser is closing too fast. Here is my code: @HostListener('window:beforeunload', ['$event']) onBeforeUnload(): boolean { let logout: any; logout = logout(); while (logout = false) { console.log("session not ended") } return true; } public async logout(): Promise<boolean> { this.userSessionService.EndSession(this.userSessionId); this.oauthService.logOut(false); return true; } What I want to happen is when a user