Search...

Tuesday, February 19, 2013

Detecting browser close event in javascript

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Detecting browser close event in javascript</title>
</head>
<body>
    <form id="form1" runat="server">
  
    </form>
</body>
</html>

<script language="javascript" type="text/javascript">
function closeEditorWarning() {
            return 'Are you sure?'
        }
window.onbeforeunload = closeEditorWarning;
</script>

*******************************************************************************

using System;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Session.Timeout = 3;//in minute
    }
}

No comments: