- Creating a Basic Dialog Window
- Using a Dialog Window as a Popup
- Working with Buttons
- Conclusion
Using a Dialog Window as a Popup
A jQuery Mobile dialog window can also be used as popup window. The main difference between a dialog window and a popup is that a dialog window typically requires some sort of feedback in the form of a button interaction, for example. A popup window can contain anything[md]for example, an image gallery, video, copy, and so on.
The following example shows how an image can be loaded in a popup window using jQuery Mobile:
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>jQuery Mobile: Popup Window</title> <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.css" /> <script src="https://code.jquery.com/jquery-1.7.1.min.js"></script> <script src="https://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.js"></script> </head> <body> <div data-role="page"> <div data-role="header"><h1>Dialog Test</h1></div> <div data-role="content"> <p><a href="#internal-popup" data-rel="dialog">Open hidden content as popup</a></p> </div> <div data-role="footer">Copyright</div> </div> <div data-role="page" id="internal-popup"> <div data-role="content"> <img src=”/path-to/image.jpg” /> <p>Image caption can go here</p> </div> </div> </body> </html>
Dialog (or popup) windows include a close button by default that leads you back to the parent web page. The nice thing about this is that you don’t need to program a close button or add any extraneous code to your web page.