Juris Upenieks
Juris Upenieks

Reputation: 13

Jquery mobile active page

Web-dev newbie reporting in:

I'm writing my first mobile app using jquery mobile and currently stuck there:

For some additional functionality, I would like to get url of current active page. I found out that it can be done using $.mobile.activePage . For example, following code works as expected for me:

$(document).on("pagecreate",function(){
    console.log($.mobile.activePage[0].baseURI);
}); 

However, when I press "back" button, Uncaught TypeError: Cannot read property 'activePage' of undefined appears in console and app hangs.

Question: how do I handle this situation? Thanks!

Upvotes: 1

Views: 993

Answers (1)

Gajotres
Gajotres

Reputation: 57309

You should do this a little bit different, use this code:

$(document).on("pageshow",'.ui-page',function(){
    console.log($.mobile.activePage[0].baseURI);
}); 

Working example: http://jsfiddle.net/Gajotres/vds2U/82/

Upvotes: 1

Related Questions