Fabio a écrit :
I know the syntax for variable "variabletopass" in ASP:
But I don't know asp
www.destinationpage.asp?variable=<%=variabletopass%>
What's the syntax for Javascript?
To send variable :
location.href = '
www.destinationpage.asp?variable='+myVariable;
To querry string :
var url = self.location.search;
// will return : '?variable=trucmachinchose'
To get value with an alone variable :
myVariable = url.split('=')[1];
i.e. :
<body onload="alert('variable = '+self.location.search.split('=')[1])">
How I do with several variables (direct script in head) :
<html>
<script type="text/javascript">
var url = self.location.search.toString();
if(url.indexOf('?')==0) {
url = url.substring(1)
if(url.indexOf('&')>0)
{
var vars = url.split('&');
for(var i=0; i<vars.length; i++)
{
var v = vars
.split('=');
alert(v[0]+' = '+v[1]);
eval(v[0] +'="' + v[1] + '"');
}
}
else
myVariable = url.split('=')[1];
}
</script>
<body onload="alert('variable = '+self.location.search.split('=')[1])">
<a href="?">example zero</a>
<a href="?avar=ASM">example one</a>
<a href="?avar=ASM&Name=Moriaux&Surname=Stephane">example two</a>
<a href="#"
onclick="if(typeof(myVariable)!='undefined')
alert('myVariable = '+myVariable);
else
if(typeof(vars)!='undefined')
alert('name = '+Name);
else alert('no variable');
return false;">control</a>
</body>
</html>