2
  • I have a page A containing 2 children iFrames called B and C.
  • A and B are on different domains.
  • On pressing a button in B I would like to change C's URL.

Based on the law III of Michael Mahemoff it should work, but in fact it doesn't (js security error).

Here is the JS code in B:

window.parent.frames['C'].location.href = "http://random.url";
Oded
501k102 gold badges900 silver badges1k bronze badges
asked Apr 2, 2010 at 11:36
0

2 Answers 2

3

This does not work because frame B cannot access the frames collection in page A.

I cannot think of any workaround (other than setting document.domain)

answered Apr 2, 2010 at 11:40
Sign up to request clarification or add additional context in comments.

1 Comment

and you can only adjust document.domain within certain constraints.
0

in case a page & frame are not on the same domain, you'll have to use postmessage, which is part of html5 and works in all modern browsers (including IE8).

if you need support for older browsers (specifally IE6/7), you could use the jQuery postmessage plugin (which transparently falls back to some nice hash-tag trickery for older browsers).

answered Apr 4, 2010 at 4:07

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.