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.Var iable1 = true;
Error:Access is Denied
Does anyone have any ideas on how to fix this error?
Thanks in Advance
<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.Var
Error:Access is Denied
Does anyone have any ideas on how to fix this error?
Thanks in Advance
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.
ASKER
It is all from the same domain (site).
Actually all the pages are even in the same directory on the same domain.
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)
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)
Just call it XSS (cross site scripting)
try window.parent instead of parent
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
tammieR,
The variable isn't part of the document object it is part of the window object. Try using ...
parent.Frame1.window.Varia ble1 = true;
Let me know if you have any questions or need more information.
b0lsc0tt
The variable isn't part of the document object it is part of the window object. Try using ...
parent.Frame1.window.Varia
Let me know if you have any questions or need more information.
b0lsc0tt
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
bol
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.