Reputation: 37
So I have something like this
<li><a href="new/page">Something</li>
<li><a href="#">Something else</li>
I want to be able to click one of the items, and send the current URL with so I can get it in the new page. I cannot store the current URL in the session because I will be going to a different location that doesn't have the same session. This is why I think that I want to have some sort of POST data so I can just send the URL or location along with it. I would like to keep it an <a>
tag because that is how the style is set.
Upvotes: 1
Views: 2589
Reputation: 2230
Try: <a href="new/page?variable=data">
. When you are ready to extract the variable on another page, you can use something like this:
var myData = getQueryVariable("variable");
if(myData){
console.log(myData);//to verify it
}
function getQueryVariable(variable) {
var query = window.location.search.substring(1);
var vars = query.split("?");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if (pair[0] == variable) {
return pair[1];
}
}
console.log('Query Variable ' + variable + ' not found');
}
Upvotes: 1
Reputation: 393
HTTP GET solution from PHP:
<li><a href="new/page?from=<?php echo $PHP_SELF?>" Something</li>
Maybe you can also rely on info from the http-referer headline.
Upvotes: 0