Related Posts Plugin for WordPress, Blogger...

About

Follow Us

Monday 6 April 2015

Introduction
In this article I will explain how to use jqyery to show alert when we try to close webpage or try to leave webpage. Alert will be appearing which will ask “Leave this page or stay on this page”.
Following function we will use to show alert message while leaving from webpage 
<script type="text/javascript">                                                                                      
    $(function () {
        $(window).on('beforeunload', function () {
            return '';
        });
    });
</script>

Full Source Code For sample Application:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Show Alert Message while closing from webpage window</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
    $(function () {
        $(window).on('beforeunload', function () {
            return '';
        });
    });
</script>
</head>
<body>
<form id="form1">
<div>
<b>Welcome to mazik Solutions</b>
</div>
</form>
</body>

</html>
Categories:

0 comments:

Post a Comment