How to use the jqm.page.params.js plugin?

I am working with jQuery mobile and I am trying to pass variables in one page.

<a href="page2.html?var1=foo&var2=bar">link1</a>
<a href="page2.html?var1=something&var2=bbq">link2</a>

      

After clicking on the link, the page will be placed in the DOM. I realize that I will have to reload the page in order for the new variables to be applied, but I have not had success with this:

$.mobile.changePage("page2.html", {reloadPage : true,});

      

When loading the page, I use the following:

$(document).delegate('#page2','pageinit', function(){           

   $.mobile.changePage("page2.html", {reloadPage : true});          

});

      

The above code will just take the page in a continuous loop, which is clearly not what I want. I tried to output the changePage from the side of the page, but the reason it is needed inside the page is for the back button to work. So, I thought that maybe I could get the variables from the url, so I tried the following with jqm.page.params.js :

$(document).delegate('#page2','pageinit', function(){           

   if ($.mobile.pageData && $.mobile.pageData.proj_id){
      console.log("Parameter var1=" + $.mobile.pageData.var1);//does not print at all.
   }

   console.log("Parameter obj =" + $.mobile.pageData); // prints NULL           

});

      

I found in the documentation a link to a plugin that will supposedly allow you to use parameters in the jqm.page.params.js url , but there are no examples on how to use this plugin.

Is there anyone here who knows how to use this plugin? Or is there a better way to pass variables when you are on the same page, referencing the same page, but with different variables?

+3


source to share


1 answer


I think it's pageinit

too early, so the parameters are not analyzed. Try it pagebeforeshow

for your listener.



See the answer to this question .

+2


source







All Articles