Skip to content

Commit 8ddf48f

Browse files
author
Dave Gurnell
committed
Finish fixing #214 - workaround for bug in IE8 iframe onload implementation
Reorder the code that sets up the iframe onload handler to ensure the handler is defined before the iframe is added to the window.
1 parent 223bc24 commit 8ddf48f

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

lib/FileAPI.XHR.js

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -96,29 +96,6 @@
9696
// legacy
9797
options.upload(options, _this);
9898

99-
xhr = document.createElement('div');
100-
xhr.innerHTML = '<form target="'+ uid +'" action="'+ url +'" method="POST" enctype="multipart/form-data" style="position: absolute; top: -1000px; overflow: hidden; width: 1px; height: 1px;">'
101-
+ '<iframe name="'+ uid +'" src="javascript:false;" onload="' + onloadFuncName + '()"></iframe>'
102-
+ (jsonp && (options.url.indexOf('=?') < 0) ? '<input value="'+ uid +'" name="'+jsonp+'" type="hidden"/>' : '')
103-
+ '</form>'
104-
;
105-
106-
// get form-data & transport
107-
var
108-
form = xhr.getElementsByTagName('form')[0]
109-
, transport = xhr.getElementsByTagName('iframe')[0]
110-
;
111-
112-
form.appendChild(data);
113-
114-
api.log(form.parentNode.innerHTML);
115-
116-
// append to DOM
117-
document.body.appendChild(xhr);
118-
119-
// keep a reference to node-transport
120-
_this.xhr.node = xhr;
121-
12299
var
123100
onPostMessage = function (evt){
124101
if( ~url.indexOf(evt.origin) ){
@@ -169,6 +146,29 @@
169146
}
170147
};
171148

149+
xhr = document.createElement('div');
150+
xhr.innerHTML = '<form target="'+ uid +'" action="'+ url +'" method="POST" enctype="multipart/form-data" style="position: absolute; top: -1000px; overflow: hidden; width: 1px; height: 1px;">'
151+
+ '<iframe name="'+ uid +'" src="javascript:false;" onload="' + onloadFuncName + '()"></iframe>'
152+
+ (jsonp && (options.url.indexOf('=?') < 0) ? '<input value="'+ uid +'" name="'+jsonp+'" type="hidden"/>' : '')
153+
+ '</form>'
154+
;
155+
156+
// get form-data & transport
157+
var
158+
form = xhr.getElementsByTagName('form')[0]
159+
, transport = xhr.getElementsByTagName('iframe')[0]
160+
;
161+
162+
form.appendChild(data);
163+
164+
api.log(form.parentNode.innerHTML);
165+
166+
// append to DOM
167+
document.body.appendChild(xhr);
168+
169+
// keep a reference to node-transport
170+
_this.xhr.node = xhr;
171+
172172
// send
173173
_this.readyState = 2; // loaded
174174
form.submit();

0 commit comments

Comments
 (0)