How to check browser close or not when browser [X] button is clicked ?

If we want to check browser close or not and depend on that we want to perform some task then you can check it easily using below function.

function CheckBrowser() 
{ 
    if(window.event.clientX < 0 && window.event.clientY <0) 
    { 
       window.open("Task.aspx", "Brwser Close Task",'left=1000,top=1000,width=50,height=10'); 
    } 
}