Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

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

irt.org | Knowledge Base | JavaScript | Misc | Q160 [ previous next ]

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

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

  • Using cookies
  • Using the location search property
  • Using frames
  • Using hidden form fields - although I have not tested this out yet
  • Using the location hash property - although doesn;t work on very old browsers

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?'


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.