onbeforeunload

Strategies for preserving form data ( on tab/browser close )

I have an issue with a task management application where occasionally users close their browsers/tabs and the information which they type goes away because they accidentally close a browser/tab, resulting in the loss of the text which they've entered ( and some can spend half an hour entering in text ). So I have to provide a solution, ...

Google chrome onbeforeunload wrong behavior with iframe

Let say I have two pages. One of them contains another one inside as iframe. If you subscribe to onbeforeunload event on the parent page, then this event doesn't triggers if you close tab when iframe is in focus. I suppose it is a bug as written here: Google Chrome issues But I mentioned that, for example, google docs handle this situa...

Internet Explorer calling window.onbeforeunload on window.open and AJAX calls

Ok, I have spent a while on this problem and this is what I have gathered: If you make an AJAX call in IE7 and you have a window.onbeforeunload function specified, it calls the onbeforeunload function. If you try to open a new window with window.open WITHOUT disturbing the current window, the onbeforeunload gets called. Does anyone k...

window.onbeforeunload not firing in child window

I want to bind a function to the beforeunload event of a child window in Javascript. I have the following code: newWind = window.open(settings.url, "Dialog", "width=" + settings.width + ",height=" + settings.height + ",resizable=" + settings.resizable + ",scrollbars=" + true); newWind.onunload = function() { alert('test'); } Works fi...

Can I prevent onbeforeload from being called when clicking on an anchor tag?

In head: <head> <script type="text/javascript"> $(document).ready(function() { $("#anchor_id").click(clickHandler); window.onbeforeunload = confirmExit; }); function clickHandler() { /* hide/show some hidden div's */ $("body").append("<p>Hi there</p>"); ...

Prevent onbeforeunload from being called when clicking on mailto link

Is there anyway to prevent onbeforeunload from being called when clicking on mailto link in chrome. In FF, Safari, IE it is working fine. <html> <head> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"&gt; google.load("jquery", "1.3.2"); </script> <script type="text/javascript"> ...

How to avoid onbeforeunload preventing Watir test from exiting

I have a webpage that uses onbeforeunload to prompt the user for confirmation whenever they try and navigate away from the page. This confirmation even fires when the browser window is closed. My problem is that this prompt is preventing Watir from closing IE at the end of a test run, at least until I manually intervene and click "OK". ...

How to click on onbeforeunload prompt in Watir test?

I have a webpage that has an onbeforeunload script that prompts the user when they take an action that would navigate away from the current page. How do I interact with this popup using Watir? My current approach looks like this: $ie.link(:text, 'Dashboard').click_no_wait hwnd = $ie.enabled_popup(10) assert(hwnd, 'The expected \'leave...

window.beforeunload called twice in Firefox - how to get around this?

I'm creating a popup window that has a beforeunload handler installed. When the "Close" file menu item is used to close the popup, the beforeunload handler is called twice, resulting in two "Are you sure you want to close this window?" messages appearing. This is a bug with Firefox, and I've reported it here, but I still would like a wa...

Setting onbeforeunload on body element in Chrome and IE using jQuery

I have a system where I want to check with the user if they're sure they want to leave the page once a dirty flag is set. I'm using the following code - In FireFox, I can look at the page source through FireBug and the tag correctly has the onbeforeunload attribute inserted in it. In Chrome and FireFox, this doesn't happen though an...

jQuery UI Dialog OnBeforeUnload

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

Why is OnBeforeUnload firing twice with asp:LinkButton?

I have the following Jquery function to notify the user with a prompt when they have unsaved changes (similar to how SO does it) and are trying to leave the current screen. <!-- in my aspx page --> <script type="text/javascript" language="javascript"> window.onbeforeunload = function() { if (HasPendingUpdates()) ...

Javascript synchronous AJAX timeout

My Javascript needs to send some data to a server when the page closes, which I currently do with a synchronous AJAX (SJAX?) request in window.onbeforeunload. The problem with this, of course, is that if my server takes too long or the network connection dies, the browser freezes. From what I've read, it's not possible to specify a time...

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

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

onbeforeunload dilemma: iframe breaking vs. annoying message on refresh/back buttons click

I'm implementing a search service called SearchInsideOut. http://bit.ly/97SFyW This search service simply replaces web page results by full web pages (Yes, I used iframe). The problem I have to deal with is iframe-breaking pages. The promising solution I found is using onbeforeunload to let users decide whether to stay or leave my site....

onBeforeUnload and multiple forms

Hi everyone, I want to have a feature to submit several forms on a page when the user leaves the page. There is this "do you wanna save?" question and my code so far is like this: function checkForChanges( ) { if (window.formform1Changed == true) { if (window.asked == false) { window.asked=true; doSave = confirm("Wann...

window.onbeforeunload is being triggered in the iFrame (CKEDITOR buttons)

On a page where I have a CKEDITOR text editor I have the following code to prevent the user from leaving the page and losing all their data: window.onbeforeunload= function() { if (CKEDITOR.instances.stuff.getData().length > 0 && oktoquit == false) { return "You have unsaved changes. Click Cancel now, then 'Save' to save the...

How to reliably send a request cross domain and cross browser on page unload

I have javascript code that's loaded by 3rd parties. The javascript keeps track of a number of metrics, and when a user exits the page I'd like to send the metrics back to my server. Due to XSS checks in some browsers, like IE, I cannot do a simple jquery.ajax() call. Instead, I'm appending an image src to the page with jquery. Here's t...

Excluding clicks within a DIV from a window.onbeforeunload

Given the following function: window.onbeforeunload= function() { if (CKEDITOR.instances.stuff.getData().length > 0 && oktoquit == false) { return "You have unsaved changes. Click Cancel now, then 'Save' to save them. Click OK now to discard them."; } }; I'd like a way to exclude this function from running if the user ...

How to display onbeforeunload dialog when appropriate?

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