onbeforeunload

Browser waits for ajax call to complete even after abort has been called (jQuery)

六眼飞鱼酱① 提交于 2019-11-26 17:38:51
问题 I have some (potentially) long-running ajax calls that I would like to abort if the user navigates to another page. The following jQuery code calls abort on all pending XMLHttpRequest objects upon navigating away from the page: $.ajaxSetup({ beforeSend: function(xhr) { $(window).bind('beforeunload', function() { xhr.abort(); }); } }); In a test case, I force a 10-second wait on the server-side operation being called. Using Firebug, I confirmed that the above code does indeed cause all pending

jQuery UI Dialog OnBeforeUnload

丶灬走出姿态 提交于 2019-11-26 17:27:49
I have a small problem. I'm attempting to catch the OnUnLoad Event of the Window and ask a confirmation question and if the user decides they want to stay then fine, and if they want to leave the page then they'll lose all unsaved data. Here's the issues... I'm using a jQuery UI Dialog and when I put the following code on my page, I have the Dialog open, and when I click the back button on the browser, it never pops up the msgbox. It just refreshes the page: <script type="text/javascript"> $(window).bind('beforeunload', function() { alert('you are an idiot!'); } ); </script> And the solution

Is the onbeforeunload event not supported on iPhone?

和自甴很熟 提交于 2019-11-26 17:23:51
问题 So, I've got a handy little bit of functionality in place in a jQuery Mobile app that lets the user know if he/she is navigating away from the page, as this will trigger a log off. In simplified form: $(window).bind('beforeunload', function() { return "Navigating away from this page will log you off. Are you sure you want to continue?"; }); $(window).unload(function() { logoff(); }); This works just great in both Safari and Chrome on my laptop. However, it doesn't appear to work on the iPhone

How to display onbeforeunload dialog when appropriate?

主宰稳场 提交于 2019-11-26 17:07:32
问题 I've got an editor in javascript on my webpage and I would like to ask user if he/she wants to leave the page even if there are unsaved changes. I know I can add custom message to the "onbeforeunload dialog" this way: window.onbeforeunload = function() { return 'You have unsaved changes!'; } (Source) but I want to display the dialog only where there really are some unsaved changes. How to do that? Thanks! 回答1: You can do something like this: var unsavedChanges = false; window.onbeforeunload =

jQuery beforeunload custom pop up window for leaving a page

落花浮王杯 提交于 2019-11-26 16:33:57
问题 Hi I would like to customize my pop up for leaving a page, is there any simple way to do that? I am using simple jQuery $(document).ready(function() { var myPopUp = $('#pop-up').css('display', 'block'); $(window).bind('beforeunload', function(){ return 'load my pop up here instead of the default browser message'; }); }); my html for the pop up is which is hidden by default <div id="pop-up"> <h2>Are you sure wanna leave</h2> <a href="#">Leave</a> <a href="#" class="close">Stay</a> </div>

Does onbeforeunload event trigger for popup.html in a google chrome extension?

别说谁变了你拦得住时间么 提交于 2019-11-26 16:10:47
问题 I'm writing a google chrome extension with a popup and a background page. The popup subscribes to certain events that the background generates, and I would like to unsubscribe from those events when the popup goes away. However, I don't see either of onbeforeunload or onunload events being generated from the popup. Are these events fired? If not, any ideas on how to capture popup close? 回答1: "beforeunload" is not fired for browser action popups. Believe me, I tried. "unload" should be fired

Way to know if user clicked Cancel on a Javascript onbeforeunload Dialog?

╄→尐↘猪︶ㄣ 提交于 2019-11-26 15:20:54
I am popping up a dialog box when someone tries to navigate away from a particular page without having saved their work. I use Javascript's onbeforeunload event, works great. Now I want to run some Javascript code when the user clicks "Cancel" on the dialog that comes up (saying they don't want to navigate away from the page). Is this possible? I'm using jQuery as well, so is there maybe an event like beforeunloadcancel I can bind to? UPDATE : The idea is to actually save and direct users to a different webpage if they chose cancel You can do it like this: $(function() { $(window).bind(

onbeforeunload confirmation screen customization

梦想的初衷 提交于 2019-11-26 14:52:31
问题 Is it possible to create a custom confirmation box for the onbeforeunload event in a browser? I tried but then I get 2 confirmation boxes (one from me which is nothing more than return confirm... and then the standard one from the browser). At the moment my code looks like: var inputChanged = false; $(window).load(function() { window.onbeforeunload = navigateAway; $(':input').bind('change', function() { inputChanged = true; }); }); function navigateAway(){ if(inputChanged){ return 'Are you

Send AJAX to server beforeunload [duplicate]

ⅰ亾dé卋堺 提交于 2019-11-26 14:30:02
问题 This question already has answers here : JavaScript, browsers, window close - send an AJAX request or run a script on window closing (9 answers) Closed 2 years ago . So supposedly starting at Firefox > 4, binding the window jQuery object to beforeunload doesn't work anymore. What'd I'd like to do is submit an AJAX post to delete my server's memcache data. When I refresh the only open tab, I can see that the beforeunload event is called in both firefox and chrome with the following code as

window.onbeforeunload not working on the iPad?

别来无恙 提交于 2019-11-26 12:55:42
Does anyone know if the onbeforeunload event is supported on the iPad and/or if there's a different way to use it? I've tried pretty much everything, and it seems like the onbeforeunload event is never triggered on the iPad (Safari browser). Specifically, this is what I've tried: window.onbeforeunload = function(event) { event.returnValue = 'test'; } window.onbeforeunload = function(event) { return 'test'; } (both of the above together) window.onbeforeunload = function(event) { alert('test')'; } (all of the above functions but inside <body onbeforeunload="..."> All of these work on FF and