How to detect browser close when browser [X] is clicked ? or Window Close Event of Browser
aspx page:
<script type="text/javascript" language="javascript">
window.onbeforeunload = closeit;
function closeit() {
var closeEvent = false;
//alert(event.clientY);
if (event.clientY < 0)
closeEvent = true;
if ((closeEvent)) {
document.getElementById('btnClose').click();
}
}
</script>
<table>
<tr>
<td>
<asp:Button ID="btnClose" runat="server" OnClick="closebrowser"
Style="display: none" />
</td>
</tr>
</table>
c# page:
public void closebrowser(object sender, EventArgs e)
{
try
{
// do something
}
catch (Exception ex)
{
throw ex;
}
}
<script type="text/javascript" language="javascript">
window.onbeforeunload = closeit;
function closeit() {
var closeEvent = false;
//alert(event.clientY);
if (event.clientY < 0)
closeEvent = true;
if ((closeEvent)) {
document.getElementById('btnClose').click();
}
}
</script>
<table>
<tr>
<td>
<asp:Button ID="btnClose" runat="server" OnClick="closebrowser"
Style="display: none" />
</td>
</tr>
</table>
c# page:
public void closebrowser(object sender, EventArgs e)
{
try
{
// do something
}
catch (Exception ex)
{
throw ex;
}
}
No comments:
Post a Comment