Link to home
Start Free TrialLog in
Avatar of tammieR
tammieR

asked on

How to update a javascript variable through frames?

I have a page that has 4 frames. Frame 1 is called for example Page1 and it has all my variables defined like so:
<script>
      var Variable1;
      var Variable2;
</script>

Now in Frame 4 I have a page that I want to update Variable1 in Frame1 and this is the code I have:

parent.Frame1.Variable1 = true;

But as I move through my application and Frame 4 is being updated I receive this javascript error:

Error:Permission Denied

I tried this and got this error:
parent.Frame1.document.Variable1 = true;
Error:Access is Denied

Does anyone have any ideas on how to fix this error?
Thanks in Advance




Avatar of enachemc
enachemc
Flag of Afghanistan image

I think you are trying to access a frame that is not from the same site as the second frame. This is prohibited because of security considerations. It's called cross domain scripting and it's not allowed.
Avatar of tammieR
tammieR

ASKER

It is all from the same domain (site).
Actually all the pages are even in the same directory on the same domain.
This is a security measure to stop websites (eg. in adverts) from sending document.cookie or some other important thing to their website.

I think that you could achieve this by writing to, and retrieving from, "document.cookie" for both pages. document.cookie can be accessed by the whole subdomain name (eg. my.website.com can access cookies from my.website.com/anything but not your.website.com, website.com nor my.webbiesite.com)
@enachemc:
Just call it XSS (cross site scripting)
try window.parent instead of parent
ASKER CERTIFIED SOLUTION
Avatar of mark-b
mark-b
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of b0lsc0tt
tammieR,

The variable isn't part of the document object it is part of the window object.  Try using ...

parent.Frame1.window.Variable1 = true;

Let me know if you have any questions or need more information.

b0lsc0tt
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Assuming the pages are the same domain, my code will work.  Even from child frame to another child frame.  The problem was just using the wrong object, document should've been window.  Let me know if you have a question.

bol
Avatar of tammieR

ASKER

Thanks to everyone who answered and helped. I gave mark-b the majority of the points, because his answer worked, but I gave mmeisinger some points because I am going to use his example for the frameset code. b0lsc0tt I tried your code and it still gave me the access denied error, and all pages are on the same domain. Thanks again to everyone for the help and examples.