onbeforeunload

Testing onbeforeunload events from Selenium

I'm trying to write a Selenium test for a web page that uses an onbeforeunload event to prompt the user before leaving. Selenium doesn't seem to recognize the confirmation dialog that comes up, or to provide a way to hit OK or Cancel. Is there any way to do this? I'm using the Java Selenium driver, if that's relevant. ...

How can I override the OnBeforeUnload dialog and replace it with my own?

I need to warn users about unsaved changes before they leave a page (a pretty common problem). window.onbeforeunload=handler This works but it raises a default dialog with an irritating standard message that wraps my own text. I need to either completely replace the standard message, so my text is clear, or (even better) replace the ...

onbeforeunload in Opera

Hi, I'm using the code that netadictos posted to the question here. All I want to do is to display a warning when a user is navigating away from or closing a window/tab. The code that netadictos posted seems to work fine in IE7, FF 3.0.5, Safari 3.2.1, and Chrome but it doesn't work in Opera v9.63. Does anyone know of way of doing th...

Running server-side function as browser closes

Background: I'm creating a very simple chatroom-like ASP.NET page with C# Code-Behind. The current users/chat messages are displayed in Controls located within an AJAX Update Panel, and using a Timer - they pull information from a DB every few seconds. I'm trying to find a simple way to handle setting a User's status to "Offline" when ...

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

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 ma...

Can I pop up a confirmation dialog when the user is closing the window in Safari/Chrome?

In IE and FF, i can attach an event handler to onBeforeUnload, and by passing a string to a property of the event, the user will see a dialog asking him whether he wants to continue with the "unloading" (either closing the window or navigating away). Safari and Chrome don't support onBeforeUnload, and onUnload seems to be too late. Is t...

Detecting whether user stayed after prompting onBeforeUnload

In a web app I'm working on, I'm capturing onBeforeUnload to ask the user whether he really wants to exit. Now, if he decides to stay, there are a number of things I'd like to do. What I'm trying to figure out is that he actually chose to stay. I can of course declare a SetTimeout for "x" seconds, and if that fires, then it would mean ...

Activating OnBeforeUnload ONLY when field values have changed

Hey guys, What I'm trying to achieve is to Warn the user of unsaved changes if he/she tries to close a page or navigate away from it without saving first. I've managed to get the OnBeforeUnload() dialog to pop-up... but I don't want it to be displayed at all if the user hasn't modified any field values. For this, I'm using this hidd...

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

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...

Why is my onbeforeunload handler causing an "Unspecified error" error?

I am using the following JavaScript function within IE6: window.onbeforeunload = function() { if (itemChanged) { return 'You have made changes to data on this page. If you navigate away from this page without first saving your data, the changes will be lost.'; } }; But when I press the Cancel button on the dialog, I ...

ASP.NET AJAX suppress onbeforeunload for AJAX requests from updatepanel

I am hooking the window.onbeforeunload event in an aspx page. I need that not to fire if I page a GridView that's in an UpdatePanel on the same page. I have tried hooking the PageRequestManager's initializeRequest event but this fires too late, i.e. after onbeforeunload. I have also tried checking PageRequestManager.get_isInAsyncPostBa...

Firefox shows issue with window.onbeforeunload event

When using onbeforeunload function, I don't want to show warning message for submit button and some other buttons also inside my form. I am checking boolean[T/F] condition to fire it. It works with IE, but it seems not checking the condition in FireFox. It is showing problem. Can somebody help. Thanks ...

ASP.NET, jQuery, dirty forms, and window.onbeforeunload

In my ASP.NET web app, I'm trying to create a universal way of warning users before navigating away from a form when they've made changes, using jQuery. Pretty standard stuff, but after a lot of searching I have yet to find a technique that works. Here's what I have at this point: addToPostBack = function(func) { var old__...

JavaScript + onbeforeunload

Hello, I have a query regarding my application. Whenever user closes browser window accidentally I'd want to do some clean up operations before that. I have used onunload event but problem is this event is sometimes is firing and sometimes doesn't. What should I do, is there better way to handle such type of problem. ...

Capturing URLs within the beforeunload event

When a user navigates away from my page the onBeforeUnload event triggers a confirmation box to be displayed to the user. At this point is there a method by which I can capture the URL that the user is navigating to? ...

Javascript and onbeforeunload?

I have <span class="cssButton"><a href="javascript:void(0);" class="buttonBlue" onclick="swfu.startUpload();"> <img src="http://uber-upload.com/img/icons/up_16.png" alt=""/> Uber-Upload! </a></span> And i want to make it so that if you press that button, it also sets a variable that makes it so that if you try to leave the page, it wi...

onbeforeunload confirmation screen custumization

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() { win...

Dealing with unsaved form data when user closes the browser

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 t...

how can i clicked a link in diffrent frames without firing onbeforeunload in the other frames

i have a web page that contain two frames such as menu at the left side and content at the right side. in the content frames, i've used onbeforeunload function that fires whenever user want to close that webpage if they do not fill all the information. the problem is, onbeforeunload fires when i click on menu's frame. is there any way to...

"Unknown Exception" when cancelling page unload with "location.href"

I'm capturing the window.onbeforeunload event using the following code: window.onbeforeunload = function (evt) { if(checkIsDirty()) { var message = 'If you continue your changes will not be saved.'; if (typeof evt == 'undefined') { //IE evt = window.ev...