How to Show Message Box On Window Close Button?

banner

Example showing popup message box

This post will make you learn about the steps that will help you in showing message box on window close button. You can read and find the way to show message box or confirm box on window close event.

I seen that many users searches for the examples that shows a message box or information box or confirm box on window close event or when user want to leave a page.

Are you tired of searching for the message box on the window close button?

Then learn how to create message boxes by visiting our webpage. The whole process is explained in detail.

Input controls on form

So, the following is the simple example which shows a popup message box when user trying to close a window tab or browser window using top right close button of browser or refresh the page.

<script type="text/javascript"> $(window).bind('beforeunload', function (e) { // Your code and validation if (confirm) { return "Are you sure you want to close this window ?"; } }); <script>

The above java-script shows message box in IE like this. It will display with default message of browser. Chrome, Firefox and other browsers will show different message.

messagebox1

The following second method is used when you have any input controls on form. This code detects form state changed or not. It will use J-Query Form Serialize function, which collects all form inputs and save it in array.

<script type="text/javascript"> // Save form current state on Load of page $('#form').data('serialize', $('#form').serialize()); // If form state change show warning Messagebox, else don't show anything. $(window).bind('beforeunload', function (e) { if ($('#form').serialize() != $('#form').data('serialize')) return "Please confirm that you saved the data on this form."; else e = null; }); <script>

The above java-script shows message box in IE like this.

messagebox2

Asp.net application development India experts have shared this tutorial to make you learn how to show message box on window close button. If you have doubts or want to ask anything related to this topic, make comments and wait for the response of the experts.

Author bio-

Akshita is a content writer who writes on many asp.net related topics and this is one of them. You can share your thoughts regarding this post with her and tell if she has skipped anything important.

For further information, mail us at [email protected]

Related article

In any software product, the aspect of Security perhaps plays the most important part.

This article is describing how to make Searchable Rad Combo Box using the Web Service.

Plug-in guides the browser that new functionality has been added. You just have to download the plug-in once to your browser.

DMCA Logo do not copy