When digging through a script that achieves AJAX file uploads with a hidden iframe, I discovered these lines:
[CODE] if(window.ActiveXObject) {
var io = document.createElement(‘<iframe id=”hiddenFrame” name=”hiddenFrame” />’);
}
else {
var io = document.createElement(‘iframe’);
io.id = ‘hiddenFrame’;
io.name = ‘hiddenFrame’;
}
I’ve never observed the first method before: passing an actual HTML tag string like “<iframe id= . . . ” to createElement.
Through some tests, I confirmed if I try to use ONLY this method for all browsers, it indeed does not work where ActiveXObject doesn’t exist. And if I try to use only the proper DOM method and set the ID/name with property syntax (like in the “else” section), in IE the form that is targeted toward the iframe does not post to it, but rather opens an entirely new window and posts to that.
Does anyone know more about this? What browsers support this use of createElement? Why won’t a “target” attribute in IE find an element whose ID has been set like “el.id = ‘something'”? And what is the relevance of the ActiveXObject check?