Trapping jQuery Mobile Dialog Open And Close

I needed to trap the events triggered when a dialog is opened and closed in a jQuery Mobile app. After trying all sorts of combinations of open, close, and dialog events, I found that these will do the trick:

view plain print about
1// Dialog opened
2$('#myDialog').on("pageshow", function() {
3    alert("Opened");
6// Dialog closed
7$('#myDialog').on("pagehide", function() {
8    alert("Closed");

Comments (3)

  • Chris Stahl

    The only problem with this solution is that it requires the jQuery on() method which requires jQuery 1.7 and JQM uses 1.6.4. Hopefully they'll get JQM fully supporting 1.7 soon as this would solve a lot of my problems!

    #1Posted by Chris Stahl | Jan 24, 2012, 10:59 AM
  • Ben Forta

    In jQuery 1.6.4 use .live(), it'll work as well.

    #2Posted by Ben Forta | Jan 24, 2012, 11:02 AM
  • Tanveer

    Hi, thanks for this code, actually i was implementing jquery autocomplete in dialog, but it was not working at all. then i use this script to register my code snippet. and it works


    #3Posted by Tanveer | Jun 12, 2012, 03:49 AM