/    Sign up×
Community /Pin to ProfileBookmark

Using createElement() with tag string?

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’;
}[/CODE]

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?

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@tarsusauthorFeb 19.2009 — Great link! Thanks!

Still not sure about the check for ActiveX. Maybe that's just intended as a way to sniff for IE. At any rate, that article told me the most important thing I wanted to know: The DOM-compliant method doesn't work in IE because IE doesn't allow the "name" attribute to be changed after the element exists.

Rather than mess with the multiple methods, I'll probably go with a solution using innerHTML on a parent element to create the iframe. Thanks again!
Copy linkTweet thisAlerts:
@felgallFeb 19.2009 — It is probably intended as a check for JScript.

A better way would be to use JScript conditional comments to check for JScript properly instead of assuming that ActiveX and JScript always go together.
×

Success!

Help @tarsus spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...