2

Have asked two questions and not getting an answer and having spent a few hours trying to find the answer without success I am wondering if someone can finally help me.

I need to generate dynamic urls and pass through parameters on jquerymobile.

example..

<a href="menu.php?id=2">Menu 2</a>
<a href="results.php?id=4">Result No. 4</a>

The above urls need to be dynamic and I need to be able to pass through a parameter of ID.

I then need to get the id parameter on the given page.

I have read lots regarding changePage etc but I can specify in the function which page will be next as it needs to be dynamic. I also need the ajax transitions to work so ajax-false needs to be true.

Please help once and for all and provide me with sample code.

Kind Regards.

2
  • So you want to navigate from page A (with some links similar to what you've posted) to page B and in page B, you want to be able to pick up the ID which was in the URL? Commented Jul 30, 2013 at 12:48
  • Not sure if you're still looking for a solution to this but I created a plug-in for this Commented Apr 1, 2014 at 21:27

2 Answers 2

1

Ok, to get the url parameter on the page you navigated in, use something similar to the following.

It uses pageshow event to get the ID from the current URL.

I have used the function from the answer on this question - Get escaped URL parameter:

$(document).on("pageshow", function(event, data) {
    var id = getURLParameter("id"); 
    console.log("ID = " + id);
});

function getURLParameter(name) {
    return decodeURI(
        (RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]
    );
}
Sign up to request clarification or add additional context in comments.

1 Comment

Brill I will try it out, clearly I have been over thinking it!
0

If the above regex doesn't work means try with this change

function getURLParameter(name) {
return decodeURI(
    (RegExp(name + '=' + '(.+?)(&|$)').exec(window.location.href)||[,null])[1]
);

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.