faqts : Computers : Programming : Languages : JavaScript : Links

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

20 of 57 people (35%) answered Yes
Recently 4 of 10 people (40%) answered Yes

Entry

How do I pass a variable from one HTML page to another using the query string of a URL. I don't want to pass a literal but the contents of a variable

May 1st, 2001 13:50
Colin Fraser, Rod Fletcher, comp.lang.javascript


This is actually simple, as long as you get all the right bits in the 
right places. I needed to display additional information in a popup 
screen for a tutorial, so I created an array of strings, the detail, in 
the popup screen to be displayed by script. It was called from the page 
by an anchor that looked similar to a traditional Windows help popup, 
like this: 
<a HREF="javascript:ddef('explanations')" 
style="text-decoration:none;color:#009933;font-weight:bold;">explanation
s</a> 
This referenced a function called ddef() data definitions that looked 
like:
<script type="text/JavaScript" language="JavaScript">
 <!-- 
//Embedded Javascripts  placed here
//a function to provide data definitions in popup screens 
function ddef(word){
myHelp=window.open('popup1.htm'+'?'+word,'helpWindow','scrollbars=yes,st
atus=no,width=350,height=400,screenx=100,screeny=100,top=100,left=100'); 
}
-->
</script>
This produces a popup screen of 350px by 400px at about the grid ref 
100,100 in both browsers. (BTW this did not work in IE4.x but it does in 
IE5.x.) The function sends the variable, word, to the popup1 document 
where it is read into an array and a result is displayed. I am pretty 
certain I got this from comp.lang.javascript, but I cant be sure.  
I hope this answers your question.