JQuery Mobile - How to get data url in pagebeforechange event

I would like to get the URL of the page that caused the page change. Any ideas?

$(document).bind("pagebeforechange", function ( event , data) { // get the data-url of the link that triggered the page change }); 
+6
source share
3 answers

You can get the page from which the user enters the data object:

 $(document).bind("pagebeforechange", function ( event , data ) { console.log(data.options.fromPage.attr('data-url')); });​ 

Note that since you are attached to the document element, and not to one data-role="page" element, which will fire twice for each page change, once for fromPage and once for toPage . The data passed to the event handler for each page event will be the same as the data for another page.

Here is a demo: http://jsfiddle.net/Atfrf/2/

+8
source

The attr method does not work in some browsers, so you better use the jqmData method. JqmData can work in any namespace.

$(document).bind("pagebeforechange", function ( event , data ) { console.log(data.toPage.jqmData('url')); });​

+2
source

Why can't you do $(this).parent('div[data-role|="page"]').attr('data-url')

0
source

Source: https://habr.com/ru/post/909196/


All Articles