jQuery Mobile - Popup on Multiple Pages



Description

You can use the same popup on the multiple pages by specifying the popup as a child of the body element using the data-demo-html attribute.

Example

Following example demonstrates the use of popup across multiple pages in the jQuery Mobile Framework.

<!DOCTYPE html>
   <head>
      <title>Popup on Multiple Pages</title>
      <meta name = "viewport" content = "width = device-width, initial-scale = 1">
      <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-1.11.3.min.js"></script>
      <script src = "https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
      
      <script id = "popup_script">
         $(function() {
            $( "#popup_page" ).enhanceWithin().popup();
         });
      </script>
   </head>
   
   <body>
      <div id = "popup_page" data-theme = "a">
         <ul data-role = "listview">
            <li>Global Menu</li>
            <li><a href = "#first_page">First Page</a></li>
            <li><a href = "#second_page">Second Page</a></li>
            <li><a href = "#third_page">Third Page</a></li>
         </ul>
      </div>
     
      <div data-role = "page" id = "first_page" class = "jqm-demos">
         <div role = "main" class = "ui-content jqm-content">
            <h2>Example of same popup on multiple pages</h2>
         
            <div data-demo-html = "#popup_page,#second_page,#third_page" 
               data-demo-js = "#popup_script">
               <a href = "#popup_page" data-rel = "popup" class = "ui-btn ui-btn-inline 
                  ui-corner-all">Click to see menu items</a>
            </div>
         
         </div>
      </div>
   
      <div id = "second_page" data-role = "page">
         <div data-role = "header">
            <a href = "#popup_page" data-rel = "popup">Menu</a>
            <h2>Second Page</h2>
         </div>
      
         <div role = "main" class = "ui-content">
            <p>This is second page.</p>
         </div>
      </div>
   
      <div id = "third_page" data-role = "page">
         <div data-role = "header">
            <a href = "#popup_page" data-rel = "popup">Menu</a>
            <h2>Third Page</h2>
         </div>
      
         <div role = "main" class = "ui-content">
            <p>This is third page.</p>
         </div>
      </div>
   </body>
</html>

Output

Let's carry out the following steps to see how the above code works −

  • Save the above html code as jqm_popup_across_multiple_pages.html file in your server root folder.

  • Open this HTML file as http://localhost/jqm_popup_across_multiple_pages.html and the following output will be displayed.

jquery_mobile_widgets.htm
Advertisements