Jump to content

Accessing parent js code from iframe


Dan06

Recommended Posts

I have an iframe and when it loads I want it to run js code from a file which is linked to the parent document. Currently, I get an error message stating:

parent.ImgUpload is not a function

 

The iframe html code is (simplified):

<html>
<head>
<script src="..." type="text/javascript"></script>
</head>
<body>
<iframe name="imgUploadFrame" id="imgUploadFrame"></iframe>
</body>
</html>

 

The js code in the iframe that is supposed to run the js code from the parent is:

window.onload = function() { parent.ImgUpload(); }

 

Help appreciated.

Link to comment
https://forums.phpfreaks.com/topic/137093-accessing-parent-js-code-from-iframe/
Share on other sites

using the following in FireFox works fine...

 

<html>
<head>
<script src="script.js" type="text/javascript"></script>
</head>
<body>
<iframe name="imgUploadFrame" id="imgUploadFrame" src="frame.php"></iframe>
</body>
</html>

<html>
  <script>
    window.onload = function() { parent.ImgUpload(); }
  </script>
  <body>
    Hello World!
  </body>
</html>

function ImgUpload ( ) {
alert('hi');
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.