iframe无法正常工作

iframe无法正常工作

本文介绍了Internet Explorer表单提交目标,iframe无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用隐藏的iframe方法提交文件而不加载新页面,它可以在除Internet Explorer之外的每个浏览器上运行,这很奇怪来自其他顶级浏览器。

I'm using the hidden iframe method of submitting files without loading a new page, and it works on every browser except Internet Explorer, which is strange coming from an otherwise top-notch browser.

表单和iframe如下所示:

The form and iframe look like this:

<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中工作的页面,在doc类型或表单中没有明显的差异和iframe结构。

I have another page that DOES work in IE, with no discernible differences in the doc type, or form and iframe structure.

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

It's also not the headers from the upload page because I tried setting the action of the working form to the upload page of the non-working one and it still worked in IE.

函数提交正在返回true。

The function submitting is working an returns true.

编辑:

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

For the sake of brevity, this isn't working either:

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

edit: This is completely ridiculous. I copied the working page verbatim into the non-working page and it still didn't work. The ONLY difference was the directory, and the .htaccess files were identical.

推荐答案

我遇到了这个问题,经过多次尝试,它只在这里解释了:

I had this problem and after many attempts, it was solved only as explained here:

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

basically, iframe needs to be created this way:

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

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

I also found out frame names for current window are stored in window.frames. In IE11, the property .name is empty for all iframes in windows.frames :O

我手动修复如下:

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

然后,你可以使用目标名称来获取帧数。

Then, you can get to frames using target name.

这篇关于Internet Explorer表单提交目标,iframe无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 23:26