jQuery appendto and append not functioning in IE8?
I'm encountering a weird issue using jQuery's append and appendTo function. I am running through an object and creating elements based on the objects properties. A few places in my function, I use the .append() and .appendTo() methods perfectly fine. However in IE8 and IE7 i get a weird error. The error disappears when I comment out the line: o.append(em)
Any ideas?
embedWindowsMedia: function(url, destination, opt){
// Default MediaPlayer options:
var d = {
id: 'mediaPlayer',
width: '320',
height: '285',
classid:'CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95',
codebase: 'http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701',
standby: 'Loading Microsoft Windows Media Player components...',
type: 'application/x-oleobject',
params: { fileName : '',
animationatStart : 'true',
transparentatStart : 'true',
autoStart : 'false',
showControls : 'false',
loop : 'true',
windowlessVideo: 'true'
},
embed: {
type: 'application/x-mplayer2',
pluginspage: 'http://microsoft.com/windows/mediaplayer/en/download/',
id: 'mediaPlayer',
name: 'mediaPlayer',
displaysize: '4',
autosize:'-1',
bgcolor:'darkblue',
showdisplay: '0',
showstatusbar:'-1',
videoborder3d:'-1',
width: '320',
height: '285',
src: '',
autostart:'',
loop :'false'
}
};
// Handle overwriting default options:
if (!url)
return false;
else{
d.params.fileName = url;
d.embed.src = url;
}
alert("urls set");
if (opt.embed){
d.embed = $.extend(d.embed, opt.embed)
delete opt.embed;
}
if (opt.params){
d.params = $.extend(d.params, opt.params)
delete opt.params;
}
var n = $.extend(d,opt);
// Create object with options and all:
var o = $("<object/>");
for (var k in n){
if (typeof n[k] == 'string'){
o.attr(k,n[k]);
}
else if(typeof n[k] == 'object'){
if (k=='params'){
for( var p in n[k]){
var param = $('<param/>');
param.attr('name', p).attr('value', n[k][p]).appendTo(o);
}
}
else if (k=='embed'){
var em = $('<embed/>');
for( var e in n[k]){
em.attr(e, n[k][e]);
}
o.append(em);
}
}
}
// Insert object into container:
if(destination)
o.appendTo(destination);
}
Getting the same exact error with the following code too:
embedWindowsMedia: function(url, destination, opt){
// Default MediaPlayer options:
var d = {
id: 'mediaPlayer',
width: '320',
height: '285',
classid:'CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95',
codebase: 'http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701',
standby: 'Loading Microsoft Windows Media Player components...',
type: 'application/x-oleobject',
params: { fileName : '',
animationatStart : 'true',
transparentatStart : 'true',
autoStart : 'false',
showControls : 'false',
loop : 'true',
windowlessVideo: 'true'
},
embed: {
type: 'application/x-mplayer2',
pluginspage: 'http://microsoft.com/windows/mediaplayer/en/download/',
id: 'mediaPlayer',
name: 'mediaPlayer',
displaysize: '4',
autosize:'-1',
bgcolor:'darkblue',
showdisplay: '0',
showstatusbar:'-1',
videoborder3d:'-1',
width: '320',
height: '285',
src: '',
autostart:'',
loop :'false'
}
};
// Handle overwriting default options:
if (!url)
return false;
else{
d.params.fileName = url;
d.embed.src = url;
}
alert("urls set");
if (opt.embed){
d.embed = $.extend(d.embed, opt.embed)
delete opt.embed;
}
if (opt.params){
d.params = $.extend(d.params, opt.params)
delete opt.params;
}
var n = $.extend(d,opt);
// Create object with options开发者_C百科 and all:
var o = $("<object/>").appendTo(destination);
for (var k in n){
if (typeof n[k] == 'string'){
o.attr(k,n[k]);
}
else if(typeof n[k] == 'object'){
if (k=='params'){
for( var p in n[k]){
var param = $('<param/>');
param.attr('name', p).attr('value', n[k][p]).appendTo(o);
}
}
else if (k=='embed'){
//var em = $('<embed/>');
var em = "<embed ";
for( var e in n[k]){
em += e+'="'+n[k][e]+'" ';
//em.attr(e, n[k][e]);
}
em+= "></embed>";
//$("#mediaPlayer").append(em);
}
}
}
console.log(em);
$("#mediaPlayer").html(em);
}
Error happens here in jquery (this.appendChild( elem );)
append: function() {
return this.domManip(arguments, true, function( elem ) {
if ( this.nodeType === 1 ) {
this.appendChild( elem );
}
});
},
Instead of appending "o" into destination at the end try this in your code. I think this will work.
var o = $("<object/>").appendTo(destination);
and comment this lines
// Insert object into container:
if(destination)
o.appendTo(destination);
Just use .html() function of jquery.
For populating <ul id="List"></ul>
, for example:
var ListItems = $("#List");
ListItems.html('');
var liString = "";
//.forEach may not work in IE8, so use "for"
for (var i= 0; i<SubjectsArray.length; i++)
{
var entry = SubjectsArray[i];
liString += "<li>"+entry+"</li>";
};
ListItems.html(liString);
精彩评论