Hi. I am working on a script that is part of displaying a video feed on a web page (with php and javascript). I design on a linux machine running firefox. For the last few days I have been trying to figure out how to make this work in IE. There is something wrong, but I can't make stupid Internet Explorer to give me any sensible error messages. var my_div = null; var newObject = null; var newParam = null; var newEmbed = null; var d = null; var element = null; var id = null; var autoPlay = null; function getBrowserName() { var browserName = ""; var ua = navigator.userAgent.toLowerCase(); if ( ua.indexOf( "opera" ) != -1 ) { browserName = "opera"; } else if ( ua.indexOf( "msie" ) != -1 ) { browserName = "msie"; } else if ( ua.indexOf( "safari" ) != -1 ) { browserName = "safari"; } else if ( ua.indexOf( "mozilla" ) != -1 ) { if ( ua.indexOf( "firefox" ) != -1 ) { browserName = "firefox"; } else { browserName = "mozilla"; } } return browserName; }; function showMovie(id, autoPlay) { if (document.getElementById("movie")) { this.removeMovie("movie"); } var browser = this.getBrowserName(); newObject = document.createElement("object"); newObject.setAttribute("id","movie"); newObject.setAttribute("height","$height"); newObject.setAttribute("width","$width"); newParam = document.createElement("param"); newParam.setAttribute("name","movie"); newParam.setAttribute("value", "http://www.youtube.com/v/"+id+"&autoplay="+autoPlay+"&hl=en"); newParam2 = document.createElement("param"); newParam2.setAttribute("name", "wmode"); newParam2.setAttribute("value", "transparent"); newEmbed = document.createElement("embed"); newEmbed.setAttribute("src", "http://www.youtube.com/v/"+id+"&autoplay="+autoPlay+"&hl=en"); newEmbed.setAttribute("type","application/x-shockwave-flash") newEmbed.setAttribute("wmode", "transparent"); newEmbed.setAttribute("height", "$height"); newEmbed.setAttribute("width", "$width"); my_div = document.getElementById("parent"); my_div.appendChild(newObject); newObject.appendChild(newParam); newObject.appendChild(newParam2); newObject.appendChild(newEmbed); } function removeMovie(element) { var browser = this.getBrowserName(); object = document.getElementById("movie"); if (browser == "firefox" || browser == "mozilla" || browser == "opera" || browser == "safari") { while (object.childNodes[0]) { object.removeChild(object.childNodes[0]); } } if (browser =="msie") { object.removeNode(true); } }
Ok, so I got myself Microsoft Script Debugger to help me trace errors in Internet Explorer. Turns out IE is kicking on my dynamic creation of an <embed> tag. I'll try to hard-code the video element tags, and append them instead. If I get it to work I'll post what I did for reference
I have hardcoded something like this in HTML: <object id="movie"> <param id="movieinfo"></param> <param id="wmode" value="transparent"></param> <embed id="embed" type="application/x-shockwave-flash" wmode="transparent"></embed> </object> Then I e. g. tried to do this with javascript: newObject = document.getElementById("movie"); newEmbed = document.getElementById("embed"); newEmbed.setAttribute("src", "http://www.youtube.com/v/"+id+"&autoplay="+autoPlay+"&hl=en"); newEmbed.setAttribute("height", "$height"); newEmbed.setAttribute("width", "$width"); my_div = document.getElementById("parent"); my_div.appendChild(newObject); newObject.appendChild(newEmbed); ...which obviously didn't work. How can I do this? What I want to do is make for instance the embed tag that I hardcoded from <embed id="embed"></embed> into <embed id="embed" src="http://mynicesource.com"></embed> without having to make the tag itself, because IE returns an error if I do, but I'm thinking I might work around it by just adding to the existing tag. Does this make any sense?
Erm... nevermind... I'm such a noob :-D Of course, all I had to do was src = newEmbed.setAttribute("src","http://www.whatever.com"); newEmbed.appendchild("src") for instance. So thank you me for answering my question. Oh, don't mention it.