Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q160 Can you access global variables (such as MyName) from a different page than where it is held?

You are here: irt.org | FAQ | JavaScript | Misc | Q160 [ previous next ]

There are four means of passing data from one page to another:

There are loads of articles/examples on this site that describe the first three options.

Far and away the best is the 2nd method:

<script language="JavaScript"><!--
function nextpage(href,string) {
    location.href = href + '?' + string;
}

<a href="javascript:nextpage('apage.html',MyName);">Next Page<\/a>

And then in the next page:

<script language="JavaScript"><!--
if (location.search.length > -1)
    document.write("Hello, " +  location.search.substring(1));
//--></script>

NOTE: the above technique "appears" to fail in Internet Explorer 3 and 4. If it does fail, this is because you are attempting this offline. Once you move your pages online it will work.

Feedback on 'Q160 Can you access global variables (such as MyName) from a different page than where it is held?'

©2018 Martin Webb