I am making a new soccer-themed website for my boss. He's a coach and wants to have soccer-related YouTube videos embedded, for his kids to watch. Rather than have 10 clips embedded, I have a list of all the clips. Upon clicking each link, the appropriate video will load on the page.
I have accomplished this by using Javascript's .innerHTML function to rewrite only the div that contains the movie. This way the users don't have to reload the entire page. It functions fine on FF, Opera and IE7, but not in IE6, and I can't figure out why. I have done some testing and IE6
is rewriting the div contents fine, but as soon as I try to rewrite and include an <embed> tag, IE6 does nothing.
I'm not sure what's going wrong and any help would be much appreciated.
Relevant code:
[HTML File]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title></title>
<link rel="stylesheet" type="text/css" href="css/general.css" />
<script language="javascript" type="text/javascript" src="includes/video.js"></script>
</head>
<body>
<div id="main">
<div id="subheader">
<img src="images/header_videos.gif" width="110" height="45" alt="Videos" title="Videos" />
</div>
<div id="video_list">
<div id="video_list_header">
Click the links below<br /> to watch a video.
</div>
<div id="video_list_text">
<a href="#view" onclick="play_video('FU4Edue4n9A')">Brazilian Soccer Schools #1</a><br />
<a href="#view" onclick="play_video('mBOUZmtx6JM')">Great Goalkeeper Moments</a><br />
<a href="#view" onclick="play_video('M3S-mOvN2Xs')">Soccer Skills</a>
</div>
</div>
<a name="view" />
<div id="video">
<div style="text-align: center; padding-top: 75px; color: #FFFFFF;">Please select a video from the list on the left.</div>
</div>
</div>
</body>
</html>
[video.js]
function play_video(id)
{
document.getElementById('video').innerHTML = 'Loading video... One moment please.';
var embed_text = '<object width="425" height="350">' +
'<param name="movie" value="http://www.youtube.com/v/{MOVIE_ID}"></param>' +
'<param name="wmode" value="transparent"></param>' +
'<embed src="http://www.youtube.com/v/{MOVIE_ID}" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed>' +
'</object>';
embed_text = embed_text.replace(/{MOVIE_ID}/g, id);
document.getElementById('video').innerHTML = embed_text;
}
Posts
Did you view your source so see if IE6 was converting any of your symbols like " or < to their web-safe counterparts?
The company I work for uses a Rich Text editor that uses InnerHTML and in IE6 it constantly rewrites special characters like TM to &trade automatically.
--
I don't see anything wrong with your JavaScript.
Solutions other than InnerHTML:
Iframe it in. Yes, evil, but this is a small audience site, and it still works in most major browsers
Modify SWFObject's embed to allow you to rewrite the target DIV with an onclick event handler? so.write is just a function call that rewrites the contents of a DIV layer with an appropriate <embed>. I don't see any reason why it can't be executed on an event handler, though I have not tried it.
we also talk about other random shit and clown upon each other