[Javascript] Passing variables from one page to another

Matt Warden mwarden at gmail.com
Wed Dec 27 12:42:10 CST 2006


On 12/27/06, tedd <tedd at sperling.com> wrote:
> There are several ways that I can pass variables between pages in
> php, such as to use sessions or cookies, but those are required
> because the operations are server-side and thus stateless.

There is nothing about server-side that makes it stateless. The
interaction between client and server is what is stateless, thus
things are stateless from the perspective of the client as well (it
must maintain state itself).

> What I want is a way for javascript (client-side) to pass variables
> from one web page to another. It seems to me that a client-side
> operation should be able to provide for this.
>
> For example, if I declare var a=1; in the index page (init on load),
> then how can I find out what it's value is in the contact page? Or is
> my thinking here too fuzzy?

You're looking at cookies or sessions. Either set the cookie directly
via JS, or use a trick like:

var a = 1;
(new Image()).src = '/myscript.php?a='+ a;

Then myscript.php can set the cookie or use session.

-- 
Matt Warden
Cleveland, OH, USA
http://mattwarden.com


This email proudly and graciously contributes to entropy.



More information about the Javascript mailing list