[thelist] Passing global vars to an iframe

Barney Carroll barney.carroll at gmail.com
Mon Nov 30 10:42:16 CST 2009

Hello list!

Wanted to get comment and advice regarding a method I've developed for
passing global javascript variables from a parent to an iframe. The idea is
to paste variables into a query string and append this to the url of the
iframe, and parse these back on the other side. Host code example:

<iframe src="iframeAd.html" class="passGlobalVars" width="252"
 <script type="text/javascript">
var queryString, iframes, i;

queryString =
'globalVars&' +
'variableA=' + variableA +
 'variableB=' + variableB +

 iframes = document.getElementsByTagName('iframe');

 if(iframes[i].getAttribute('class') &&
iframes[i].getAttribute('class').indexOf('passGlobalVars') > -1){
if(iframes[i].src.indexOf('?') > -1){
 iframes[i].src = iframes[i].src + '&' + queryString;
} else {
 iframes[i].src = iframes[i].src + '?' + queryString;

And code in the receiving iframe:

<script type="text/javascript">
var globalVars, i;

if(document.location.href.indexOf('globalVars') > -1){
globalVars =

if(typeof(window[globalVars[i].split('=')[0]]) === 'undefined'){
 window[globalVars[i].split('=')[0]] = globalVars[i].split('=')[1];

I'm wanting to send every global variable to the iframe. Does anyone know of
a non eval-method to round up all global variables and paste their name and
value into a string to define my queryString a bit more programmatically?

Barney Carroll

barney.carroll at gmail.com
07594 506 381

More information about the thelist mailing list