jquery-archive / jquery-mobile

jQuery Mobile Framework
https://jquerymobile.com
Other
9.7k stars 2.41k forks source link

Need to know the url that changePage is going to beforepageshow/create #1325

Closed rmanalan closed 13 years ago

rmanalan commented 13 years ago

In my phonegap app, I have pages that execute page specific JS when the page is loaded. Some of them have a need to know the query params used to get that page. Using location.href won't work since the hashChange hasn't happened yet when the page specific js is called. Similar to $.mobile.activePage, I think it would be useful to have a way for devs to access the location.href of the page that is being fetched.

Currently, I have workaround this by setting a property on my global object:

wc.currentHref = location.href;
$('a').live('vclick', function() {
  wc.currentHref = $(this).attr('href');
});

Is there a better way to do this? If not, can we have something set inside of $.mobile that gives us the same info?

scottjehl commented 13 years ago

When pagebeforeshow is triggered, the target page will have a data-url attribute on it containing the filepath from which it was retrieved. Does that help?

$("div").live("pagebeforecreate", function(){
    var url = $(this).jqmData("url");
});
rmanalan commented 13 years ago

This works. Thanks.

On Thu, Mar 31, 2011 at 7:38 PM, scottjehl < reply@reply.github.com>wrote:

When pagebeforeshow is triggered, the target page will have a data-url attribute on it containing the filepath from which it was retrieved. Does that help?

$("div").live("pagebeforecreate", function(){ var url = $(this).jqmData("url"); });

Reply to this email directly or view it on GitHub: https://github.com/jquery/jquery-mobile/issues/1325#comment_943975