Click to See Complete Forum and Search --> : variables follow by the link


ahlofan
10-10-2003, 04:05 AM
Dear all experts:

i want to leave some information at the client's machine so that a specific site can get those information~ is it possible? Firstly, cookies can't do that? is there anything can do the simular stuff?

and I have one more question. = )
how can i read the variables pass by the link by using javascript?
like this, http://www.mysite.com/page1.html?x=3

so by using javascript, how can I get the variable x?

thank you for your help! = )

nauman73
10-10-2003, 06:33 AM
Hi

Not sure how to accomplish your first task, i.e. saving information on client system.

To catch variables passed with a link, u need to utilize the 'location' object. Check the code given below. First there is the code for a page that calls another page and passes a variable 'x' to the page called.


<html>
<head>

</head>
<body>
<a href="called.html?x=3">Call the other page</a>
</body>
</html>


Now the code for the page that is called in the link. This page is called 'called.html'


<html>
<head>
<script language="JavaScript">
function myURL()
{
var variables=location.search;
alert(variables);
}
</script>
</head>
<body>
<input type="button" value="MyURL" onclick="myURL()">
</body>
</html>


Function myURL utilises the 'location.serach' property. This property retrieves the part of link after the '?' mark. In the above code when you click the button named 'MyURL' you will get a message box showing this string.


?x=3


So basically you have captured the variable passed by the link. Of course your need to do some string manipulation to parse this variable.

Hope this helps.

Nauman

ahlofan
10-10-2003, 06:37 AM
Don't worry about the first part! i am not a good english speaker! thats why! = )
by the way, thx! to be able to read the variables follow by the link is very helpful to me already! thankyou!