Click here to Skip to main content
15,917,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, I have this code to detect when user close browser with 'close button of window'.
Works fine for me, but I have found if browser is close from taskbar then javascript is not execute.

Can Javascript recognize closing from Windows taskbar?


JavaScript
var myclose = false;
        function ConfirmClose() {
            if (event.clientY < 0) {
                event.returnValue = Do you wish to leave?';
                setTimeout('myclose=false', 10);
                myclose = true;
                        }
              }
        function HandleOnClose() {
            if (myclose == true) {
                location.replace('/contextpath/j_spring_security_logout');
                window.open("logoff.aspx")
            }
        }



Thanks in advance for help!
Posted
Updated 14-Jul-13 3:33am
v2
Comments
_Asif_ 14-Jul-13 8:54am    
What is event.ClientY?
Sampath Lokuge 14-Jul-13 9:03am    
@DejanDejanovic Check this.May be helped to you.Not sure.
http://www.codeproject.com/Articles/58835/Window-Close-Event-of-Browser
Joezer BH 14-Jul-13 9:34am    
event.returnValue = Do you wish to leave?';
Missing tag there on the string: event.returnValue = 'Do you wish to leave?';

FTFY
DejanDejanovic 14-Jul-13 14:59pm    
ClientY = Returns the horizontal coordinate within the application's client area at which the event occurred
ClientX = Returns the vertical coordinate within the application's client area at which the event occurred
DejanDejanovic 14-Jul-13 15:02pm    
@Maimonides:
I think I have delete tag when I have copy/past code, and was changing alert message. In any case, code inside of my applications has tag.

1 solution

XML
Hi,
solution was found it, which was test it with IE, Firefox, and Chrome. Only thing which developer should do about testing with Firefox, and Chrome is to turn off Blocking Pop Up option under browsers settings.

<pre lang="Javascript">
window.onbeforeunload = confirmExit;
        function confirmExit() {
            return "You have attempted to leave this page?";
            
        }
        var newWindowOpen;
                function openPopup() {
            newWindowOpen= window.open("URL", "", "");
        }
<script>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900