Customize exit operation when closing tab or browser

BlazekaMarko

Hi i'm trying to customize the operation made when a tab/browser is closed on my software. I've found a script that stop the execution of the closing operation and display a popup that ask to confirm the exit intent:

<script type="text/javascript">
    window.addEventListener('beforeunload', function(e) {
        e.preventDefault();
        e.returnValue='';
    });
</script>

I want to make this script execute other operation like showing a confirm dialog, but cant figure out how to make it. I want something like

<script type="text/javascript">
    window.addEventListener('beforeunload', function(e) {
        e.stopClosing();
        //Show confirm dialog
    });
</script>

I'm using Primefaces and JSF. Thanks

natre214

That's not possible in JavaScript because that would be a big security problem. Every browser has its own beforeunload dialog style and you can't customize it.

W3Schools says:

The default message that appears in the confirmation box, is different in different browsers. However, the standard message is something like "Are you sure you want to leave this page?". This message cannot be removed.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Alert on exit the browser and closing the tab

Detect browser or tab closing

Detect browser/tab closing

Perform an asynchronous service get when closing browser window / tab with Angular

RStudio Server on ec2 - Not persistent when closing browser tab

Confirmation before closing of tab/browser

Closing Browser Tab not working in Chrome

Send a mail on closing the browser tab

browser tab closing in selenium python

Redirect when closing tab?

Disable closing Google's Chrome browser after closing last tab

Session Lost when closing the browser

Cookie is not cleared when closing the browser

How to close the current tab of the browser in protractor with out closing the complete browser

Graceful exit when closing console window

Confirm Exit Dialog When Closing Android Studio

Close the window when closing the last tab

shortcut key for closing single tab in browser without using mouse

Avoid closing Shiny browser when an error occurs

Change to most recently used tab when closing a tab in IntelliJ IDEA?

Automatically moving to next/prev UL LI Tab when closing a tab

Is there a vscode settings which specifies which tab to open when closing a tab?

Close browser tab and exit Angular2 application

Post method in $window.unload never called on change url, closing the tab, but ran on closing the browser

How to Exit Debug Mode When Browser Closed?

Is it possible to clear all cookie at the time one closing browser/browser tab. In asp.net

Does Windows take care of closing sockets when processes exit?

Closing MongoClient connection on exit when using MongoDB Native driver?

Fire Angularjs event when tab/browser is closed