2

我正在使用隐藏的 iframe 方法来提交文件而不加载新页面,它适用于除 Internet Explorer 之外的所有浏览器,这对于其他顶级浏览器来说很奇怪。

表单和 iframe 如下所示:

<iframe id="hidden_upload" style="display:none" src="" name="hidden_upload" ></iframe>
<form class="" action="upload.php" method="post" target="hidden_upload" enctype="multipart/form-data" id="uploadForm">
    <table>
        <tbody>
            <tr>
                <td><label for = "title">Title: </label></td>
                <td><input type="text" name="title" id="title" maxlength="40" style="width:300px;"/></td>
            </tr>

            <tr>
                <td><label for="description">Description: </label></td>
                <td><textarea id="description" name="description" style="width:460px;height:135px;"></textarea></td>
            </tr>

            <tr>
                <td><label for="file">File: </label></td>
                <td><input type="hidden"  name="MAX_FILE_SIZE" value="3145728" /><input id="file" type="file" name="file"/></td>
            </tr>

        </tbody>    
    </table>
    <center><input type="submit" value="Upload" id="filesubmit" onclick="return submitting()"/></center>
</form>

我有另一个在 IE 中工作的页面,在文档类型或表单和 iframe 结构方面没有明显差异。

它也不是上传页面的标题,因为我尝试将工作表单的操作设置为非工作表单的上传页面,它仍然在 IE 中工作。

该函数submitting正在运行,返回 true。

编辑:

为简洁起见,这也不起作用:

<form class="" action="upload.php" method="post" target="hidden_upload" enctype="multipart/form-data" id="importForm">
    <input type="submit" />
</form>
<iframe id="hidden_upload" style="display:none" src="" name="hidden_upload" ></iframe>

编辑:这完全是荒谬的。我将工作页面逐字复制到非工作页面中,但仍然无法正常工作。唯一的区别是目录,.htaccess 文件是相同的。

4

1 回答 1

3

我遇到了这个问题,经过多次尝试,它仅按照此处的说明解决:

http://terminalapp.net/submitting-a-form-with-target-set-to-a-script-generated-iframe-on-ie/

基本上,iframe 需要以这种方式创建:

iframe = document.createElement('<iframe name="fileUploaderEmptyHole">');

我还发现当前窗口的框架名称存储在 window.frames 中。在 IE11 中,属性 .name 对于 windows.frames 中的所有 iframe 为空:O

我手动修复如下:

for(i=0;i<window.frames.length;i++)
 window.frames[i].name = window.frames[i].frameElement.name;

然后,您可以使用目标名称访问帧。

于 2014-07-24T19:30:46.907 回答