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


Hi

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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <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 ?");

            }
        }
    
    </script>
</head>
<body onBeforeUnload="confirmClose()"> 
    <form id="form1" runat="server">
    <div>
    
    </div>
    </form>
</body>
</html>


Advertisement

10 thoughts on “How to display alert message while closing the browser close button ?

  1. gowthaman March 8, 2013 / 5:06 am

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

    • Chandra Dev March 8, 2013 / 10:34 am

      Hi

      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. Smithe52 April 20, 2014 / 11:19 pm

    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 May 1, 2014 / 4:35 am

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

  3. John June 14, 2014 / 8:27 am

    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 June 19, 2014 / 9:03 am

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

  4. ashleyrawlings September 4, 2014 / 5:25 am

    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.

  5. makaylamarquis September 9, 2014 / 11:40 pm

    Great article, totally what I was looking for.

  6. elvirabracegirdle October 7, 2014 / 5:50 am

    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:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.