mowwwalker
mowwwalker

Reputation: 17382

Internet Explorer form submit with target to iframe not working

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.

Upvotes: 2

Views: 5479

Answers (1)

Raf
Raf

Reputation: 131

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.

Upvotes: 3

Related Questions