Web page navigation alerts

When I try to close the Google Docs tab with unsaved changes, this is what I get in my browser (FF 3.5).

Are you sure you want to navigate from this page?

You have unsaved changes to this document. Click Cancel Now, then Save to save them. Click OK now to drop them.

Click OK to continue, or Cancel, stay on the current page.

My question is whether such alerts are part of a web application (e.g. gdocs) or are they issued by the browser? If the latter, how is this done?

+52
javascript browser google-docs
Aug 17 '09 at 17:13
source share
2 answers

In the browser. This is a beforeunload event handler that returns custom dialog text that is only the middle of the three paragraphs — the other two paragraphs, as well as the button text, cannot be changed or otherwise changed.

 window.onbeforeunload = function(){ return 'Testing...' } // OR var unloadListener = function(){ return 'Testing...' }; window.addEventListener('beforeunload', unloadListener); 

A dialog box will appear

 Are you sure you want to navigate away from this page? Testing... Press OK to continue, or Cancel to stay on the current page. 

This can be reversed by setting the handler to zero

 window.onbeforeunload = null; // OR window.removeEventListener('beforeunload', unloadListener); 
+82
Aug 17 '09 at 17:19
source share

Notifications are part of the web application. Check out the source code and look at javascript.

-eleven
Aug 17 '09 at 17:15
source share



All Articles