brandonaaron/bgiframe — Issue #6: IE9 - DOM Exception: INVALID_CHARACTER_ERR (5)
Author: Philalawst
Created: 2012-02-02 08:18:56+00:00
State: open

On IE9, i get the error DOM Exception: INVALID_CHARACTER_ERR (5) On line :
``` this.insertBefore( document.createElement(html), this.firstChild ); ```

To solve the problem, i write these lines :

$.fn.bgIframe = $.fn.bgiframe = function(s) {
var html = '';
var isIE9 = /MSIE 9.0/.test(navigator.userAgent);
...
var prop = function(n){return n&&n.constructor==Number?n+'px':n;};
if( isIE9 )
{
html = document.createElement("iframe");
html.setAttribute("src", s.src);
html.setAttribute("class", "bgiframe");
html.setAttribute("frameborder", "0");
html.setAttribute("tabindex", "-1");
var style = 'display:block;position:absolute;z-index:-1;';
style += (s.opacity !== false?'filter:Alpha(Opacity=\'0\');':'');
style += 'top:'+(s.top=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderTopWidth)||0)*-1)+\'px\')':prop(s.top))+';';
style += 'left:'+(s.left=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth)||0)*-1)+\'px\')':prop(s.left))+';';
style += 'width:'+(s.width=='auto'?'expression(this.parentNode.offsetWidth+\'px\')':prop(s.width))+';';
style += 'height:'+(s.height=='auto'?'expression(this.parentNode.offsetHeight+\'px\')':prop(s.height))+';';
html.setAttribute("style",style);
}
else
{
html = '';
}

return this.each(function() {
if ( $('> iframe.bgiframe', this).length == 0) { //alert(this.firstChild);
if( isIE9 )
this.insertBefore( html, this.firstChild );
else
this.insertBefore( document.createElement(html), this.firstChild );
}
});
}
return this;
};