【问题标题】:Internet Explorer form submit with target to iframe not working带有目标的 Internet Explorer 表单提交到 iframe 不起作用
【发布时间】:2012-05-21 20:42:19
【问题描述】:

我使用隐藏的 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 文件是相同的。

【问题讨论】:

  • 我发现问题请回复,我也面临同样的问题
  • @PRASANTH,我希望我能记住做任何事都只是侥幸。无论做什么,都不要放弃。

标签: forms internet-explorer iframe submit


【解决方案1】:

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

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;

然后,您可以使用目标名称获取帧。

【讨论】:

  • 您能否引用您的来源并提供一些错误示例以及您为解决问题所做的工作。没有上下文没有人会点击你的链接。
猜你喜欢
  • 2011-07-26
  • 1970-01-01
  • 1970-01-01
  • 2012-10-06
  • 2012-02-17
  • 1970-01-01
  • 2011-08-14
  • 2011-11-26
  • 1970-01-01
相关资源
最近更新 更多