Open In App

jQuery Mobile panel beforeclose Event

jQuery Mobile is a set of HTML5 based user interface systems that is built on top of jQuery. It is used for creating responsive and accessible websites and web apps for a variety of devices like mobiles, tablets, laptops, and desktops.

In this article, we will be using the jQuery Mobile panel beforeclose event that triggers when the process of closing the panel starts.



Syntax:

Parameters: It accepts a callback function that has two parameters:

CDN links:

<link rel=”stylesheet” href=”https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css” />
<script src=”https://code.jquery.com/jquery-2.1.3.js”></script>
<script src=”https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.js”></script>

Example: In the example below, an alert box appears when the beforeclose event is fired.




<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="utf-8">
    <meta name="viewport" content=
          "width=device-width, initial-scale=1">
  
    <link rel="stylesheet" href=
    <script src=
    </script>
    <script src=
   </script>
  
    <script>
        $(document).ready(function () {
            
             // Initialize the panel with
              // beforeclose callback specified
            $("#divID").panel({
                beforeclose: function (event, ui) {
                    alert("Panel beforeclose event fired.")
                }
            });
        });
          
          // A function to close the panel.
        function closePanel() {
            $("#divID").panel("close");
        }
    </script>
</head>
  
<body>
    <div data-role="page">
        <div data-role="header">
            <h1 style="color:green;">GeeksforGeeks</h1>
            <h3>jQuery Mobile Panel beforeclose event</h3>
        </div>
  
        <div role="main" class="ui-content">
            <center>
                <a href="#divID">Open Panel</a>
            </center>
        </div>
        <div data-role="panel" id="divID">
            <button onclick="closePanel();">Close Panel</button>
        </div>
    </div>
</body>
</html>

Output:

Reference: https://api.jquerymobile.com/panel/#event-beforeclose


Article Tags :