How does one make IE9 generate a generic HTML5 node using createElementNS?

REKDRALSDAH

New Member
I'm working on some DOM comparison code, and ran into the neat problem that real HTML5 elements such as img (HTMLImageElement), audio (HTMLAudioElement) and video (HTMLVideElement) all have behaviour tacked on that you can't remove - setting a src may initiate media loading (automatic in img, automatic if the autoplay attribute exists in audio and video).This gets particularly interesting when the media is large, or in the case of video and audio, when they start autoplaying despite not being attached to the document. Mystery secondary sound sources are really, really bad =)So, to bypass everything I'm using the following JavaScript code to generate generic HTML5 nodes instead:\[code\]var node = document.createElementNS("html", "img");node.setAttribute("src", "http://your.favourite.img/lolcat.gif");\[/code\]This creates a node that has "img" as nodeName, but isn't backed by an Image or HTMLImageElement object, and thus won't trigger network traffic when "src" is assigned (of course it won't act as an image on-page, but it's not used for on-page purposes anyway).The same holds for audio and video elements. Creating them in this way sets up generic nodes with the correct node names, and will not load media even if "autoplay" is set, since they're not backed by their respective functional objects.Normally generic nodes with a bogus namespace end up being XML nodes, but with the "html" or "html5" namespace, Chrome, Firefox, and Opera all generate generic HTML5 nodes instead, which is great because it means they will serialize correctly. The generic "img" node, for instance, still serializes as\[code\]<img src='http://stackoverflow.com/questions/14486547/...'>\[/code\]rather than as\[code\]<img src='http://stackoverflow.com/questions/14486547/...'></img>\[/code\]A winner is me!Except in IE9. In IE9 (and I presume IE10, though I don't have windows 8 available to me) I cannot seem to find any namespace or alternative function that effects generic HTML5 nodes, so I'm a bit stuck. How do I create generic HTML5 nodes in IE9, serializing correctly without triggering specific element functionality?
 
Back
Top