Internet Explorer 表单提交目标到 iframe 不起作用

2023-12-22

我使用隐藏的 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。

edit:

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

<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 文件是相同的。


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

"http://terminalapp.net/submitting-a-form-with-target-set-to-a-script- generated-iframe-on-ie/ 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 中,windows.frames 中的所有 iframe 属性 .name 均为空:O

我手动修复如下:

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

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Internet Explorer 表单提交目标到 iframe 不起作用 的相关文章