开发者

Force iframe load

开发者 https://www.devze.com 2022-12-17 12:04 出处:网络
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.

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">&l开发者_如何学运维t;/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>


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消