views:

122

answers:

2

Normally I open a window with javascript to show information about a upload progress, but it doesn't look good and many users uses popup blockers.

So I thought I could show these information in an iframe, but the iframe doesn't load during the upload.

But if I open the iframe during the upload in a new window/tab if loads.

How could I force that the iframe should be loaded?

HTML:

<script type="text/javascript">
function test() {
    document.getElementById('iframe').innerHTML = '<iframe src="./stats.php?id=123456"></iframe>';
}
</script>

<form action="upload.php" enctype="multipart/form-data" method="post">
  <input id="upload" name="upload" size="30" type="file">
  <input type="submit" value="Upload File" onclick="test();">
</form>

<div id="iframe"></div>
A: 

First, give the iFrame an id, say iframe1, then run:

document.getElementById('iframe1').contentWindow.location.reload();

which is technically incorrect but widely supported, or:

document.getElementById('iframe1').contentDocument.defaultView.location.reload();

which is correct but not supported by IE.

wyatt
Okay, I get this error: FIREBUG WARNING: ReferenceError: Window is not defined
Poru
A: 

I'd hazard a guess it's because once the form is being posted, the current page won't load anything else since it's already sending data and loading the new page, upload.php.

Perhaps using an AJAX file uploader would be a better idea? Here's one I found via Google that looks good.

DisgruntledGoat
You might be right, but I already used a Ajax-Uploader and it's similar:Every Ajax-Request takes more than 10 seconds, so it's useless and I drive better with the iframe.
Poru