0

I do not get it. I thought that I didi it, and now I cannot do it. Simple html with an iframe. Indide the iframe is another html. I want to change an image from the main iframe when you access the iframe. HTML from the main html:

Main html:

<!DOCTYPE HTML>
 <html lang="en">
    <head></head>
    <body>
        <img id="logo" src="../img/fpdfilms-logo-home.png" />
        <iframe id="fondo" name="main" src="test.html"></iframe>
    </body>
</html>

test.html

<!DOCTYPE HTML>
 <html lang="en">
    <head></head>
    <body>
        <a href="#" onclick="change();">Change Picture</p>
        <script src="../js/jquery-1.11.2.min.js"></script>
        <script type="text/javascript">
            function change()
            {
                var $logo= $('#logo', window.parent.document);
                alert("Does it work?");
                $logo.attr("src","../img/fpdfilms-logo-director.png");
            }
        </script>
    </body>
</html>

It is supposed to change the picture when you click on the link. But the ALERT is not showing... I've tried different ways and I'm really lost. Is so difficult to achieve this simple change?

nanmaniac
  • 107
  • 1
  • 13
  • possible duplicate of [How to write this in jQuery "window.parent.document.getElementById('parentPrice').innerHTML"?](http://stackoverflow.com/questions/726816/how-to-write-this-in-jquery-window-parent-document-getelementbyidparentprice) – John Weisz Feb 24 '15 at 08:49

2 Answers2

0

You can refer to this answer as it does what you need with jquery.

how to access iFrame parent page using jquery?

From the above example selecting an element from an iframe in the parent document use

var $parentElement= $('#parentElement', window.parent.document);
Community
  • 1
  • 1
Jako Basson
  • 1,461
  • 12
  • 19
0

Checked your page (chrome 40) and got

SecurityError: Blocked a frame with origin "null" from accessing a frame with origin "null". Protocols, domains, and ports must match.

so I checked in a server (local express) and works fine.

yosahr
  • 14
  • 1