Results 1 to 3 of 3
-
02-16-2010, 10:46 AM #1Web Hosting Master
- Join Date
- May 2009
- Posts
- 766
window.onbeforeunload cross-browser functionality (jQuery)
Hi all,
So, I'm trying to negotiate overriding a window.onbeforeunload event.
I've got a header page that includes some basic JS for the whole site, including this bit:
Code:$(document).ready(function () { $("#loading").hide("fast"); $(window).bind('beforeunload', function () { $("#loading").show("fast"); }); if (typeof pagestart == 'function') pagestart(); });
pagestart() is just a method that I use on individual pages to initialize any handlers, etc. that are page-specific.
So, now I've got a page that checks for changes in a form and needs to pop up a confirmation dialog if the user attempts to navigate away with unsaved changes. This means that the loading div will pop up, but if they click "Cancel," obviously, we need it to go away again. Alternatively, if we just overwrite the onbeforeunload event so that the loading div does not appear until the next page starts rendering, that would be fine as well.
This does not work at all:
Code:function pagestart() { $(window).unbind('beforeunload'); $(window).bind('beforeunload', function () { if (changed) { return "You have unsaved changes on this page. Leaving the page\n" + "will result in the loss of these changes."; } }); }
Code:window.onbeforeunload = function () { if (changed) { $("#loading").hide("fast"); return "You have unsaved changes on this page. Leaving the page\n" + "will result in the loss of these changes."; } }
-
02-18-2010, 05:53 PM #2Web Hosting Master
- Join Date
- May 2009
- Posts
- 766
window.onbeforeunload cross-browser functionality (jQuery) [SOLVED]
Fix was:
Code:$(window).unload(function() { //... });
-
03-07-2012, 03:37 AM #3New Member
- Join Date
- Mar 2012
- Posts
- 3
Similar Threads
-
Site altered the size of my browser window!
By grandad in forum Computers and PeripheralsReplies: 5Last Post: 10-20-2006, 04:47 PM -
Push PDF to browser ranther than open in browser window
By SimonT in forum Programming DiscussionReplies: 2Last Post: 11-12-2005, 10:43 AM -
no white between image and browser window, how?
By macfan in forum Web Design and ContentReplies: 19Last Post: 06-21-2004, 01:11 PM -
Control Browser Window Size
By djack89 in forum Programming DiscussionReplies: 5Last Post: 11-29-2003, 03:52 AM -
controlling browser window on load
By djack89 in forum Programming DiscussionReplies: 2Last Post: 06-19-2003, 11:50 PM