Internet Explorer form submit with target to iframe not working

时间秒杀一切 提交于 2019-12-22 11:33:32

问题


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.

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>

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

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.

The function submitting is working an returns true.

edit:

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>

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.


回答1:


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

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

basically, iframe needs to be created this way:

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

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

I manually fixed like:

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.



来源:https://stackoverflow.com/questions/10692325/internet-explorer-form-submit-with-target-to-iframe-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!