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


.



Relevant Pages

  • A general solution
    ... Split on an array of delimiters; parse a file in one call. ... Hi Gerry,If the string is using comma to separate name and using quotation ... var element; ... Gerry Hickman wrote: ...
    (microsoft.public.scripting.jscript)
  • Re: Calculate the string statement
    ... verkn:(vkn:char; ... funkt:(fkt:string; ... var fkt,dfkt: p; ... var fehler: boolean; ...
    (comp.lang.pascal.borland)
  • Two new tests for MM B&V
    ... var RunningThreads: Integer; ... class function TStringThreadTest.GetBenchmarkDescription: string; ... function CheckPattern(const Dest: Pointer; const Size: Integer; const ...
    (borland.public.delphi.language.basm)
  • Re: [PHP] Image Generation
    ... the text, font, colour, maximum frame size (ie the width and height it ... var $xoffset, $yoffset, $margin; ... a string or array of strings. ... a float or an array of floats - which size to display the related text at. ...
    (php.general)
  • server-side JavaScript: Prototypes of built-in classes, objects and functins
    ... Session object (disk-based session variables for data persistence ... File class (manipulation of files on server, ie. open, close, read, ... //Methods Cgi.queryCgi.postCgi.anyby default return an empty string if requested var not found ...
    (comp.lang.javascript)