强制iframe加载

时间:2010-01-21 16:21:41

标签: javascript html

通常我用javascript打开一个窗口来显示有关上传进度的信息, 但它看起来并不好,许多用户使用弹出窗口拦截器。

所以我想我可以在iframe中显示这些信息, 但是在上传过程中iframe没有加载。

但是,如果我在上传期间在新窗口/标签中打开iframe,如果加载。

我如何强制加载iframe?

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>

2 个答案:

答案 0 :(得分:0)

首先,给iFrame一个id,比如iframe1,然后运行:

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

技术上不正确但受到广泛支持,或者:

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

这是正确的但IE不支持。

答案 1 :(得分:0)

我猜错了,因为一旦表单被发布,当前页面将不会加载任何其他内容,因为它已经在发送数据并加载新页面upload.php

也许使用AJAX文件上传器会更好看? Here's one我通过Google发现它看起来不错。

相关问题