Ryan
Ryan

Reputation: 1

jQuery Mobile -- Event Binding

I'm trying to have jQuery-Mobile execute a piece of code each time a page is shown. However, the page is generated automatically by an underlying framework which does not set an ID. This means that I can control the javascript but not the page generation. Therefore, I'm using $.mobile.activePage to bind the event pageshow without success. Why isn't this working and what would the solution be? Thanks.

$.mobile.activePage.bind('pageshow', function() { alert('message'); }

Upvotes: 0

Views: 340

Answers (1)

user235273
user235273

Reputation:

Listen to 'pagechange' event. You can get fromPage and toPage from the pagechange event.

$(document).off('pagechange');
$(document).on('pagechange', function (e, ui) {
    //triggers on page change
    console.log('from page: %o', ui.options.fromPage);
    console.log('to page: %o', ui.toPage);
});

Upvotes: 3

Related Questions