Take the 2-minute tour ×

I have a page with 3 iframes and this page loads a JS file that has

var stayFifty = new Boolean(false);

and a function that changes what it does based on this boolean.

In an iframe on this page I have an onclick function defined as

toggleFifty = function() {
    parent.stayFifty = new Boolean(!(stayFifty.valueOf()));

added to an img tag with


But when I click on the img tag, the toggleFifty function doesn't seem to fire. I believe this has something to do with how the toggleFifty function is trying to change the stayFifty variable. Can someone explain how to fix this issue and a little bit about the scope problem?

I tried using information from this link but it seems I am not understanding something.

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

You are missing the parent when you change the value of the stayFifty variable:

toggleFifty = function() {
    parent.stayFifty = !parent.stayFifty;

BTW, notice that you don't need to use Boolean constructor when working with boolean variables, and when you declare you can simply use Boolean literals:

// on your parent page
var stayFifty = false;
share|improve this answer
Thanks much. The Boolean constructors were a leftover of trying to get it to work and not knowing where to go. Can't believe that I forgot to reuse the parent.stayFifty. –  Kevin Stich Dec 6 '09 at 21:08
add comment

Your Answer


