Re: Send parameter from one HTML page to another?



Martin Honnen wrote:
Petar Popara wrote:

Is it possible to send one parameter from one HTML page to another
HTML page? For example: to send some data as part of the link from
first page: http://www.my.com/secondPage.html?mydata

and second page could receive "mydata" in JavaScript.

You can access various parts of the location object, in the above case
location.search
would be the string
?mydata
which you could then parse e.g.
location.search.substring(1)
would give you the mydata string.
If you use the usual query string format to pass data e.g.
http://example.com/whatever.html?arg1=value1&arg2=value2&arg3=value3
then check various script archives for code that parses that query
string, it has been done certainly.

This function returns the ith parameter, starting at parameter 0
function qsobj(parm)
{
var qpairs = document.location.search.substring(1).split("&")
var qvbl = qpairs[parm].split("=")
return qvbl[1] ? unescape(qvbl[1].replace(/%20|\+/g," ")) : null
}

I use it like this
<a href = "picture.html?pic=image.jpg&cap=name of
picture&height=600&width=400">

picture.html has this code
<head>
<script type="text/javascript">
var pic = qsobj(0)
var cap = qsobj(1)
var height = qsobj(2)
var width = qsobj(3)
</script>
....
</head>

Other JS code in picture.html uses the variables
pic
cap
height
width

As I understand it, the variable names passed do not have to match the
variable names used when they are retrieved.
That is the call could just as well be
<a href = "picture.html?p=image.jpg&c=name of picture&h=600&w=400">

--
Cheers,
Trevor L.
Website: http://tandcl.homemail.com.au


.