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
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');
}

Link to comment
Share on other sites

I found the problem; it was with firefox's add-on firebug. I have anther js file that onload executes two POSTs. That for some reason causes an error in firebug, which results in the iframe code not running.

 

Thanks for the help; I appreciate it.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.