Skip to content Skip to sidebar Skip to footer

"invalid Argument" In Ie 8 On Jquery.prepend() On Flash Objects

Demo page. When run in IE 8, this code yields an exception with 'Invalid argument.' as description and message, and this number: -2147024809 I'm using latest (1.7.1) jQuery. Is thi

Solution 1:

As Fresheyeball states, IE does not see <object/> as part of the DOM or rather does not allow modifications as soon it has been inserted into the document (whereas before insertion, it can be modified very well).

A plain and quite save solution to fix this is to modify the full outerHTML of the node. This will not cause a modification of the element but will remove it, recreate it, replace it and therefore not throw the above exception.

Example for jQuery:

$("object:has(> param[name=wmode][value=window]), object:not(:has(> param[name=wmode]))").each(replace);
functionreplace() {
  this.outerHTML = this.outerHTML.replace(/<(?:[^">]+|(["']).*?\1)*>/, '$&<param name="wmode" value="opaque"/>');
}

A similar re-rendering for <embed/> could be achieved as follows:

$("embed[wmode=window], embed:not([wmode])").attr("wmode", "opaque").wrap("<div/>").unwrap();

Solution 2:

I'm not 100% sure about this off the top of my head, but encountered something like this before, and it was specific to the <object> tag. IE does not see this as part of the html dom, so manipulation with jquery returns a null object. The solution I remember working was html5shiv like, create an object element and append the param as a string instead of a jQuery object and all should be well.

Alternatively, you could wrap the flash in a div, then get that div's inner html, append to that html, then drop it back into the wrapper div.

Solution 3:

The script below isn't exactly the 2 or 3 line fix I was hoping for, but I found this article very helpful. I modified it slightly and removed the check for jQuery, but it worked like a charm!

http://www.developersnippets.com/2010/12/04/how-to-add-wmodetransparent-for-flash-object-using-jquery-and-native-javascript/

Post a Comment for ""invalid Argument" In Ie 8 On Jquery.prepend() On Flash Objects"