views:

94

answers:

1

I am using a jquery plugin called colorbox, this might be irrelevent though as my colorbox just opens an iframe on screen.

So more basic I guess is, I have 3 variables on my parent window that are returned from an AJAX call with jquery:

data.response 
data.comment 
data.userid

After these are set lower down in my script I call my colorbox/iframe that opens a new page in the iframe box. I then run some code, a captcha and some other stuff hapens, I then have the iframe box close.

Now I can easily send data from the iframe using parent.variable but can't do it the other way around.

SO my question is, after closing the iframe and I am returned to my parent window, are the 3 variables data.response data.comment data.userid

Are these still available?

+2  A: 

Yes they are available until you refresh the page or unset them somewhere in your JS. You must only remember about scopes in JavaScript. If the value was defined only in the function you won't be able to access it, but if they were defined in the same scope as where you try to access them you won't have any problem with that.

$(document).ready(function() {

    var ajaxData;
    $.getJSON('url', {foo: 'bar'}, function(data) {
        ajaxData = data;
    });

    ...

    // then somewhere later (i.e. after closing the iframe)
    // notice that this is still the same scope ajaxData is defined
    if (ajaxData !== undefined) {
        console.log(ajaxData);
    } else {
        alert('data undefined');
    }
});
RaYell
thanks that is good news
jasondavis