I tried every solution posted above for my problem, and none of them worked. In my case, I have a form containing a file for upload whose target is pointed towards a static IFRAME element.
The FORM:
- <form action="upload.php" method="post" enctype="multipart/form-data" target="myIframe">
The IFRAME:
- <iframe name="myIframe" id="myIframe" src=""></iframe>
When the form submits, the file is handled by a PHP upload script. Now, in my case, I needed to have the contents of the uploaded file (an HTML page) output to the IFRAME window, like so:
- <?php echo file_get_contents($_FILES['myFile']['tmp_name']); ?>
Additionally, I needed a callback to let my controlling script in the parent window know when the IFRAME's content has loaded. As you all know, this was easy enough in a Mozilla browser. In fact, I could communicate with the parent window using at least 5 different methods! However, not a single one worked for IE.
Then some of your suggestions got me thinking about this ONLOAD attribute for IFRAMEs. Even though none of the solutions worked, I did some research. Some people have said that even though the specification allows for the ONLOAD attribute in an IFRAME element, it just doesn't work (a bug in IE?!).
Finally, I stumbled upon this page:
http://msdn.microsoft.com/en-us/libr...s.85%29.aspx#4
This commenter shows his work using Microsoft's exclusive JScript coding. It was then that the solution was quickened to me! Here is his sample code:
- <script for="window" event="onload" language="JScript">
-
window.status = "Page is loaded!";
-
</script>
This effectively binds an ONLOAD event handler to the IFRAME element! But since the above snippet is ignored by FireFox, I simply write combined code to perform my cross-browser compatible callback.
My PHP upload script, then, looks like this:
- <?php
-
echo file_get_contents($_FILES['source-file']['tmp_name']);
-
-
<script language="javascript">
-
// For Mozilla
-
parent.window.myIframe.setAttribute('onload','myCallbackFunc();');
-
</script>
-
-
<script for="window" event="onload" language="jscript">
-
// For Microsoft
-
parent.window.myCallbackFunc();
-
</script>
-
?>
I hope this helps!