2

I am using jquery, jquery mobile and html to build a mobile app using phonegap, my index.html display a list of names

 <li><a href="profile.html?id='+item.id+'"><h3>'+item.fname+' '+item.lname+'</h3></a></li> 

When user click on any person of list, the profile of that person should be displayed, I need to get the current url (profile.html?id=) to extract the id of the person, to make the database query.

I tried to use ( inside the body of profile.html)

<script> 
 url=window.location.href;
<script> 

and

   <script>
    url=document.URL;
    </script>

but both return the url of the index.html not the second page (profile.html?id=), even though the URL of page is changed to profile.html?id=2 when I tested on browser any idea?

user2814778
  • 296
  • 6
  • 14
  • u might want this http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values – Vicky Gonsalves Oct 27 '13 at 11:01
  • @Vicky Gonsalves Thank you, actually my problem wasn't how to get url query values, but to get the current url so to do ( The debug was showing the previous page url). Well, the question updated with the solution. – user2814778 Oct 30 '13 at 06:16
  • You can add that solution as an answer below and accept it, so that this question is marked as answered. – Purus Nov 19 '13 at 15:07

1 Answers1

2

After too many attempts and searches, found the solution, using

$.mobile.activePage[0].baseURI;

According to Alex Bachuk, using window.location.href will return previous page URL, while active page is inserted into the DOM via AJAX, we need to use mobile.activePage[0] to get the current page URL.

sources: http://alexbachuk.com/jquery-mobile-active-page-url/

user2814778
  • 296
  • 6
  • 14