How to load a page in one iframe using the javascript that resides in different iframe

Posted on 2014-07-11
Last Modified: 2014-07-24
A parent window contain two iframes. Lets say "iframe1" and "iframe2".
When I click on a button in iframe1, corresponding HTML should be loaded in iframe2.

I have written below code in javascript in iframe1 to accomplish that -
 parent.document.getElementsByName('iframe2')[0].src = "http://localhost/test.html";

Open in new window

This is working fine when parent window and iframes are in same domain. When they are in different domain, I am getting a javascript access error. I tried setting "document.domain" property of child iframe to the one corresponding to the parent and it didn't work.

Please suggest any alternate solutions.
Question by:Ravi Kalla
    LVL 28

    Accepted Solution

    Here is some good reading on this, some other experts may have more recent solutions as I have not worked with this in a while:
    LVL 52

    Expert Comment

    by:Scott Fell, EE MVE
    I don't think what you are trying to do is possible as you describe.  

    Just thinking out loud, what about framed site A gets updated and talks to the server and the server.  Then page that is in the other frame  has data pushed out and updates.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
    Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
    In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now