onbeforeunload

Displaying a custom dialog when the user exits the browser?

爷,独闯天下 提交于 2019-12-19 03:41:32
问题 Yes, I realize this is horrible UI and bad accessibility wise, but I am forced to seek out the options due to contracted work ( to which I didn't initially agree upon and am stuck with ). I know that you can assign an event handler to onbeforeunload like: window.onbeforeunload = function() { return 'You have unsaved changes!'; } That would bring about a dialog generated by the OS/browser which cannot be customized. It would ask you to Cancel your request or go on. So far it seems the only way

Is there any way to detect if user pressed “Stay on page” or “Leave page” in beforeunload event?

≡放荡痞女 提交于 2019-12-19 03:13:40
问题 Is there any way that I could detect in the following code that either user clicked "leave page" or "stay on page" button ? $(window).on('beforeunload', function (){ return "You save some unsaved data, Do you want to leave?"; }); 回答1: With a few hacks you can at least determine if the user stayed. If the user left the page, there's not much you can do about that : var timeout; $(window).on('beforeunload', function (){ timeout = setTimeout(function() { // user stayed, do stuff here }, 1000);

Distinguish onbeforeunload for File Download vs Page Change

雨燕双飞 提交于 2019-12-18 18:43:27
问题 I have an onbeforeunload event that's supposed to get triggered any time a user goes to a new page. It works well enough, but I've found that it also gets triggered in Chrome any time a user downloads a file from the page they're on. I'd like to be able to tell if the event is getting fired because it's being triggered by a file download. What's the best way to do that? EDIT: As a clarification, I don't own the site that I'm listening to onbeforeunload on. The event is listened to by a

Distinguish onbeforeunload for File Download vs Page Change

半城伤御伤魂 提交于 2019-12-18 18:43:06
问题 I have an onbeforeunload event that's supposed to get triggered any time a user goes to a new page. It works well enough, but I've found that it also gets triggered in Chrome any time a user downloads a file from the page they're on. I'd like to be able to tell if the event is getting fired because it's being triggered by a file download. What's the best way to do that? EDIT: As a clarification, I don't own the site that I'm listening to onbeforeunload on. The event is listened to by a

Can I prevent window.onbeforeunload from being called when doing an AJAX call

拜拜、爱过 提交于 2019-12-18 10:35:53
问题 I have an AJAX-based grid control. We hook into the window.onbeforeunload event to check if they have unsaved data and if so present them with a message "Are you sure you want to navigate away...you have unsaved data...". All this is good. But AJAX calls also trigger window.onbeforeunload and so if the grid has unsaved data and we make an AJAX call (such as to delete a row in another grid) the user gets the "Are you sure you want to navigate away...you have unsaved data..." message which is

How to handle below Internet Explorer popup “Are you sure you want to leave this page?” through Selenium

一曲冷凌霜 提交于 2019-12-18 09:24:51
问题 How to Handle below IE Popup in Selenium 回答1: The Internet Explorer popup with text as Are you sure you want to leave this page? is the result of WindowEventHandlers.onbeforeunload onbeforeunload The onbeforeunload property of the WindowEventHandlers mixin is the EventHandler for processing beforeunload events. These events fire when a window is about to unload its resources. At this point, the document is still visible and the event is still cancelable. Solution There are different

How to send an HTTP request onbeforeunload in AngularJS?

℡╲_俬逩灬. 提交于 2019-12-17 20:07:25
问题 I have a simple angular app that has two views that are loaded using ngRoute. I need to do some clean up on the server when the user navigates between views and when the user leaves the page (refreshes window, closes tab, or closes browser). My first stop was here: Showing alert in angularjs when user leaves a page. It solved the first case where the user navigates between views. I've handled the clean up like this: $scope.$on('$locationChangeStart', function (event) { var answer = confirm(

window.onbeforeunload - Only show warning when not submitting form [duplicate]

本小妞迷上赌 提交于 2019-12-17 18:26:28
问题 This question already has answers here : How to disable beforeunload action when user is submitting a form? (6 answers) Closed 4 years ago . I am using window.onbeforeunload to prevent the user from navigating away after changing values on a form. This is working fine, except it also shows the warning when the user submits the form (not desired). How can I do this without showing the warning when the form submits? Current code: var formHasChanged = false; $(document).on('change', 'form

How to disable beforeunload action when user is submitting a form?

北城以北 提交于 2019-12-17 06:48:59
问题 I have this little piece of code: <script> $(window).bind('beforeunload', function() { $.ajax({ async: false, type: 'POST', url: '/something' }); }); </script> I wonder, how could I disable this request when user hits the submit button. Basically something like here, on SO. When your asking a question and decide to close the page, you get a warning window, but that doesn't happen when you're submitting the form. 回答1: Call unbind using the beforeunload event handler: $('form#someForm').submit

How to disable beforeunload action when user is submitting a form?

不想你离开。 提交于 2019-12-17 06:48:29
问题 I have this little piece of code: <script> $(window).bind('beforeunload', function() { $.ajax({ async: false, type: 'POST', url: '/something' }); }); </script> I wonder, how could I disable this request when user hits the submit button. Basically something like here, on SO. When your asking a question and decide to close the page, you get a warning window, but that doesn't happen when you're submitting the form. 回答1: Call unbind using the beforeunload event handler: $('form#someForm').submit