How to display alert message while closing the browser close button ?


We can display the alert message using java script while closing the close button of browser like this

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">
<head runat="server">
    <script type="text/javascript">
        function confirmClose() {
            if (window.event.clientY < 0) {
                event.returnValue = "Are you sure do you want to navigate away from this page";
               // alert("are you sure ?");

<body onBeforeUnload="confirmClose()"> 
    <form id="form1" runat="server">


10 Responses to “How to display alert message while closing the browser close button ?”

  1. gowthaman Says:

    i need source code for sending sms using .. pls send source code to my mail id below

    • Chandra Dev Says:


      There is no specific code for sending sms. It is like api code which will provide by service provider. That will change depending on service provider. For this service, they will charge some money to you.

  2. gowthaman Says:

    my id

  3. Smithe52 Says:

    It’s truly a great and useful piece of information. I’m satisfied that you shared this helpful information with us. Please stay us informed like this. Thank you for sharing. dekkbdbaafecfdae

    • Chandra Dev Says:

      Thanks. I am glad to know about this. I will keep on posting helpful information.

  4. John Says:

    Hаve уou ever thoսght abߋut creating an ebook οr guest authoring օn оther sites?
    I have a blog based սpon on the sаme ideas you discuss аnd wоuld гeally liкe tο have
    you share some stories/іnformation. I know my
    audience wоuld vаlue your ѡork. If уoս’re еven remotely inteгested, feel free tߋ shoot mе аn email.

    • Chandra Dev Says:

      Yes. I am interested. Please share your web site URL.

  5. ashleyrawlings Says:

    Have you ever considered publishing an ebook or guest authoring on other blogs?

    I have a blog based upon on the same information you discuss and would really like to have you share
    spme stories/information. I know my viewers would
    value your work. If you’re even remotely interested, feel
    free to send me an e mail.

  6. makaylamarquis Says:

    Great article, totally what I was looking for.

  7. elvirabracegirdle Says:

    Thank you for sharing your info. I really appreciate your efforts and
    I am waiting for your further write ups thank you once again.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: