Dec 4, 2011

Catch Browser Close Event Javascript

In this post, I am sharing the code to catch the browser close event and write code to perform some action when the browser is closed.

Ajax is used to request the webpage when the browser is closed.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default1.aspx.cs" Inherits="Default1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head runat="server">
    <script type="text/javascript" src=""></script>
    <script language="javascript" type="text/javascript">
        function window.onbeforeunload() {
                type: "POST",
                url: "exit.aspx/OnClose",
                data: "{}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (msg) {
                    // Do something interesting here.
    <form id="form1" runat="server">
using System;
using System.Web.Services;
public partial class exit : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)


    public static void OnClose()
        //write code here

    Choose :
  • OR
  • To comment
No comments:
Write Comments