0

I have got a page called servicesDetails.html that has links.The url looks like below

../Myapp/servicesDetails.html?servicetype=Advanced&serviceid=1208

The links when clicked loads an internal page called audioListPage with some params,the link looks like this

<a href="#audioListPage?audioid=123&audiotype=mp3" class="loadAudio" data-role="button" data-mini="true" data-inline="true">

Once the audioListPage is loaded the url changes to

../Myapp/servicesDetails.html?servicetype=Advanced&serviceid=1208#audioListPage?audioid=123&audiotype=mp3

I need to display the user with the audioid and audiotype when the audioListPage loads,how do i do this?

Based on a comment below I tried this

$.urlParam = function(name){
var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
return results[1] || 0;
}

$('#audioListPage').live('pagecreate',function(event) {
   console.log($.urlParam('audioid '));//this is giving me an error
});

I checked why the error was occuring and found that window.location.href is giving me only ../Myapp/servicesDetails.html?servicetype=Advanced&serviceid=1208, not the updated URL.Im not sure if Im calling the $.urlParam() at the right event

manraj82
  • 5,929
  • 24
  • 56
  • 83

2 Answers2

0

You can just parse window.location.hash

See this example:

How can I get query string values in JavaScript?

and replace window.location.search

with window.location.hash

Community
  • 1
  • 1
sunn0
  • 2,918
  • 1
  • 24
  • 25
  • $('#audioListPage').live('pagecreate',function(event) { console.log(window.location.hash);//returns empty string }); Its returning an empty string – manraj82 Jun 29 '12 at 12:19
0

jQM Documentation suggests using one of these plugins for parameters:

jQuery Mobile does not support query parameter passing to internal/embedded pages but there are two plugins that you can add to your project to support this feature. There is a lightweight page params plugin and a more fully featured jQuery Mobile router plugin for use with backbone.js or spine.js.

Docs: ( See Known limitations section )

Phill Pafford
  • 83,471
  • 91
  • 263
  • 383