I would like to get the data-url of the page that triggered the page change. Any ideas?
$(document).bind("pagebeforechange", function ( event , data) {
// get the data-url of the link that triggered the page change
});
You can get the page from which the user is coming within the data
object:
$(document).bind("pagebeforechange", function ( event , data ) {
console.log(data.options.fromPage.attr('data-url'));
});
Note that since you are binding to the document
element rather than a single data-role="page"
element that this will fire twice for each page-change, once for the fromPage
and once for the toPage
. The data passed into the event handler for each page's event will be the same as the data for the other page.
Here is a demo: http://jsfiddle.net/Atfrf/2/
The attr method is not work at some browsers, so you'd better to use the jqmData method. The jqmData can work at any namespace.
$(document).bind("pagebeforechange", function ( event , data ) {
console.log(data.toPage.jqmData('url'));
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With