Using nickf
's example found here
I've created an element to hack together a replacement for an iframe on a site that is displayed in IE7. It's a short term stop-gap until all the computers at the office are upgraded to IE8 which is why we aren't bothering with a server-side solution.
The goal is to take YouTube embed code and transform it into the old embed code without having to replace every single video on the site.
var w = $('iframe').width(),
h = $('iframe').height(),
src = $('iframe').attr('src').split('/')[4];
$('iframe').after('<div class="iframediv"></div>');
$('<object></object>', {width: w, height: h})
.append($('<param />', {name: "movie", value: "http://www.youtube.com/v/" + src + "?hl=en_US&version=3"}))
.append($('<param />', {name: "allowFullScreen", value: "true"}))
.append($('<param />', {name: "allowscriptaccess", value: "always"}))
.append($('<embed />', {src: "http://www.youtube.com/v/" + src + "?hl=en_US&version=3", type: "application/x-shockwave-flash", width: w, height: h, allowscriptaccess: "always", allowfullscreen: "true"}))
.appendTo($('.iframediv'));
A working example of this code can be found here on jsfiddle
What I'm having trouble with is the created element is not working in IE7. It appears as though the <object>
creation code is broken and causes jQuery to stop working, yet in Chrome it works perfectly fine. I'm not sure if there is an IE7 specific workaround that I need to accomplish this?
Edit: I purposely left out the line $('iframe').remove();
for testing purposes for now.
Edit: My fix -
if($('html').hasClass('ie7'))
{
var w = $('iframe').width(),
h = $('iframe').height(),
ytsrc = $('iframe').attr('src').split('/')[4];
$('iframe').after('<div class="iframediv"></div>');
$('<embed />', {width: w, height: h, src: "http://www.youtube.com/v/" + ytsrc + "?hl=en_US&version=3", type: "application/x-shockwave-flash", allowfullscreen: "true", allowscriptaccess: "always"}).appendTo($('.iframediv'));
$('iframe').remove();
}