11 October 2011

Invalid Argument, jQuery bgiframe + position + iframe + IE6

Hi all,

Do you have an error when using jQuery bgiframe library together with jQuery UI position and your own frame? An error like: Invalid Argument. Which is actually very odd.

The problem when putting my own iframe behind a element that I want to position somewhere on the page with jQuery UI position function it throws the error. The error is thrown because jQuery UI position is automatically calling the bgiframe function if it exists. Here is the code:


Code:
if ( $.fn.bgiframe ) {
	elem.bgiframe();
}


And now the line inside the bgiframe function where it throws the error:

Code:
return this.each(function() {
        if ( $(this).children('iframe.bgiframe').length === 0 )
            this.insertBefore( document.createElement(html), this.firstChild ); // the error is thrown here
    });

I have made a workaround for myself - an ugly one but what else to do? :)
Here it is:

Code:
// Workaround - position is using the bgiframe when it exists and it fails when I have my own frame
    // If I remove my own frame - then there are problems when refreshing the content of the element that is positioned
    var tempBgiframeFunction = $.fn.bgiframe;
    $.fn.bgiframe = null;
    // end workaround
    $(positioningElement).position({
        my: "left top",
        at: "left bottom",
        of: $(element),
        collision: "fit"
    });
    // put back initial state - before workaround
    $.fn.bgiframe = tempBgiframeFunction;


Happy coding !!

No comments:

Post a Comment

your thoughts are welcome:

Need more? Leave comments and subscribe to my blog.

.