benck
benck

Reputation: 2052

How can I catch onload event when using jquery mobile dialog?

When it's a normal jquery mobile page, I can use the following code as onload function:

$(document).delegate("#page", "pageinit", function(){});

However, it's not working when a page is opened as dialog(using ). How can I catch onload event?

Upvotes: 2

Views: 4394

Answers (1)

Kiliman
Kiliman

Reputation: 20312

It depends a lot on how your page is structured. First of all your delegate call is targeting a specific id #page so if your dialog isn't using that id, then it won't be handled. You can use a more generic selector like this:

$(document).delegate('div[data-role=dialog]', 'pageinit', function() {})

I created an example that shows how to capture pageinit and pageshow for normal pages and dialogs http://jsfiddle.net/kiliman/hQh6u/1/

Upvotes: 5

Related Questions