onbeforeunload

Javascript onclose event

非 Y 不嫁゛ 提交于 2019-12-11 11:43:42
问题 How can I run javascript when user close the browser. I tried to use 'onunload', but it calls every time I press F5/refresh button? Thanks 回答1: As far as the Javascript on the page is concerned, there's no difference between closing the browser, navigating to another page or refreshing the same page. 来源: https://stackoverflow.com/questions/6494206/javascript-onclose-event

beforeunload ignores condition

ぐ巨炮叔叔 提交于 2019-12-11 11:34:47
问题 I want to detect when user is leaving browser however I need to check on some condition, the script below skips the if(false) and always prompts for request regardless of returning true or false. How can I let it check condition before prompting? <html> <head> <script type="text/javascript" src="http://code.jquery.com/jquery-2.1.3.min.js"></script> </head> <body> <script type="text/javascript"> $(document).ready(function () { $(window).bind('beforeunload', function () { if (false) return "Are

window.close() and the beforeunload event

点点圈 提交于 2019-12-11 11:24:29
问题 I need to clear some session variables whenever user closes the browser window. The window can be closed in two ways: the normal way by pressing the window close button by pressing a custom button inside the window I am using jQuery, so the listener is: // clear some session variables $(window).bind('beforeunload', function() { makeAjaxCall(some, params); }); The window is closed by calling a function that eventually executes: window.close(); The problem is that the second way to close the

Dealing with unsaved form data when user closes the browser

爷,独闯天下 提交于 2019-12-11 10:48:03
问题 I'm having hard time trying to figure out how to auto-save user data in a form when the browser is being closed or user changes the page. The onBeforeUnload event is OK when you want to open a dialog box, but by then it's too late to save the changes (except if you just block the browser in the onBeforeUnload handler long enough for it to pass the request to the server...but I'd rather not do that). I am sure some of you have had to deal with the unsaved form problem. What do you do? Do you:

Submit form before user leaves page in javascript/jquery

喜夏-厌秋 提交于 2019-12-11 10:06:22
问题 Is it possible to create a more customized leaving-page event? Right now I am using the window.onbeforeunload event to warn users of their unsaved changes before leaving the page. What I really want to do though, is to give the user the option to save their data right away before leaving the page(possibly with a button in a pop up) and then continue redirecting them. I assume it's not possible to let onbeforeunload do some extra work before displaying the message(I tried). So is what I want

Getting onBeforeUnload to work with a setTimeout

六月ゝ 毕业季﹏ 提交于 2019-12-11 07:55:13
问题 I am trying to get onbeforeunload to work with a set timer of sorts but I can't seem to get it to fire up when the return is in place. I am hoping it would work with a timer but for some reason the timer isn't working. Here is the code I am working and thank you for your help in looking at it much appreciated. var validNavigation = false; function wireUpEvents() { var leave_message = 'Leaving the page'; jQuery( function goodbye() { jQuery(window).bind('onbeforeunload', function() { setTimeout

Chrome back button terminates upload stream unexpectedly

你说的曾经没有我的故事 提交于 2019-12-11 07:16:13
问题 I'm providing users form-based file uploads (one at a time) with ajax updates/progress bars. I want to give them a heads up if they navigate away that any current upload will be canceled. The following code achieves that goal except in Chrome (v.18). If you click the back button in Chrome the file upload stream is immediately terminated, throwing a org.apache.commons.fileupload.FileUploadBase$IOFileUploadException: Processing of multipart/form-data request failed. Stream ended unexpectedly

Prevent closing browser tab when form is dirty in Angular 2

我们两清 提交于 2019-12-11 06:49:44
问题 How to prevent closing browser tab when form is dirty in Angular 2? My html body contains a component: <body> <my-app>Loading, please wait...</my-app> </body> which contains a router navigation and a router outlet: <nav> (...) </nav> <router-outlet></router-outlet> and when the router navigates to the edit page, I have some form there: <form #myForm="ngForm"> <button pButton type="text" label="Save" (click)="onSave()" [disabled]="!myForm.valid || myForm.pristine"></button> </form> Now, if the

Vaadin JavaScript unload event listener not firing

北城以北 提交于 2019-12-11 05:17:50
问题 I have a Vaadin 7 application where I need to reliably detect a user leaving or navigating away from a page in order to carry out some cleanup. My aim is to have the page pop up a confirmation dialog on browser/tab close, and if the user chooses to leave the page, then at that point I perform the cleanup operation. I am fairly inexperienced at JavaScript, but from what I have discovered 'onbeforeunload' and 'onunload' are the functions to use. At this point in time, I am using the following

img requests before windows close

£可爱£侵袭症+ 提交于 2019-12-11 04:07:43
问题 I have the situation that data needs to be reliably sent before browser window closes. My current implementation is to use a synchronous AJAX calls. However that's unlikely to work in the near future because the browsers are deprecating synchronous XHR calls according to https://xhr.spec.whatwg.org/#synchronous-flag What I'm trying is to replace the ajax call with a fake "img" call, parameterize data to be sent and append it as the image's url query string. It seemed to work so far I tried. I