Alerts when navigating away from a web page

后端 未结 2 1801
死守一世寂寞
死守一世寂寞 2020-11-30 21:40

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

Are you sure you want to navigate away from

相关标签:
2条回答
  • 2020-11-30 21:53

    By the browser. It's the beforeunload event handler that returns the customized text of the dialog, which is only the middle of the three paragraphs - the other two paragraphs as well as the text of the buttons cannot be customized or otherwise changed.

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

    Will yield a dialog that says

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

    You can nullify this by setting the handler to null

    window.onbeforeunload = null;
    
    // OR
    
    window.removeEventListener('beforeunload', unloadListener);
    
    0 讨论(0)
  • 2020-11-30 22:01

    The alerts are part of the web application. View the source code and look at the javascript.

    0 讨论(0)
提交回复
热议问题