+ Start a Discussion

Give Warning Message before closing this window or changing tab

I am using Visualforce page, for entry. I would like to prompt the user with a warning message before they close this window (give them a second chance).
I tried adding a javascript to make a call to a method, which will prompt the user. (window.onbeforeunload, window.onunload). But none of that worked. It seems like Salesforce changes the script for these events back to the default one.
Please let me know how can I give a warning message adn give another chance to the user before closing this window.
I'm not sure this is possible as the close action of a browser is not related to the code in a page.