How to show confirmation alert before closing browser tab using JavaScript

Implementation:
Add the below given script in head section of page (webform, Html).

<script type="text/javascript">
    window.onbeforeunload = function () {
        return 'Please save the changes before close the tab !!!';
    }
</script>

Complete HTML Markup of webform:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script type="text/javascript">
    window.onbeforeunload = function () {
        return 'Please save the changes before close the tab !!!';
    }
</script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <fieldset>
        <legend>JavaScript Example</legend>
        <h1>Show confirmation alert before closing browser tab using JavaScript </h1>
    </fieldset>
    </div>
    </form>
</body>
</html>

Comments

Popular posts from this blog

what is Event Cache table in sharepoint

CAML Query syntax and options in SharePoint

Change anchor link url in sharepoint calender