Reputation: 11
my problem is that everything works fine in FF but not for chrome/IE/safari. if anyone can help out it would be GREATLY appreciated!! PS: can't use iFrame.
here's the code: first part of code needs beginning script and end script since the script code won't show.
<script>
function play(clip){
document.getElementById("frame").src=
"http://www.youtube.com/v/"+clip+"&autoplay=0&rel=0";
}
</script>
<object width="375" height="295">
<param name="movie" value=""></param>
<param name="wmode" value="transparent"></param>
<param name="border" value="0"></param>
<param name="allowFullScreen" value="true"></param>
<param name="allowscriptaccess" value="always"></param>
<embed id ="frame" src="http://www.youtube.com/v/CsGYh8AacgY?version=3&hl=en_US&rel=0" type="application/x-shockwave-flash" border="0" allowfullscreen=true allowscriptaccess = always wmode="transparent" width="375" height="295"></embed>
</object><br />
<B>Choose Video:</B>
<a href="#" onclick="play('CsGYh8AacgY'); return false" style="color:#9b9898; font-size:12">Charlie 1</a> |
<a href="#" onclick="play('QFCSXr6qnv4'); return false" style="color:#9b9898; font-size:12">Charlie 2</a> |
<a href="#" onclick="play('eaCCkfjPm0o'); return false" style="color:#9b9898; font-size:12">Charlie 3</a>
Upvotes: 1
Views: 2051
Reputation: 985
Trythis,
$('a.video').click(function () {
var id = $(this).attr('data-youtube');
var src = '//www.youtube.com/embed/'+id;
var iframe = '<iframe id="youtube" width="560" height="315" frameborder="0" src="'+src+'" allowfullscreen></iframe>';
$(".video-wrapper").html(iframe);
return false;
});
https://jsfiddle.net/rakesh_vadnal/pyktnz7r/2/
Upvotes: 0
Reputation: 7848
The issue is that the movie param is not being set. However, I am not sure if setting that directly will cause the movie to reload. If you are not opposed to using some javascript libraries, this is what I would do:
<script src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
function play(clip){
var mv = "http://www.youtube.com/v/"+clip+"&autoplay=0&rel=0";
swfobject.embedSWF(mv, "myContent", "375", "295", "8");
}
$(document).ready(function() {
play('CsGYh8AacgY');
});
</script>
<div id="myContent"></div>
<br />
<B>Choose Video:</B>
<a href="#" onclick="play('CsGYh8AacgY'); return false" style="color:#9b9898; font-size:12">Charlie 1</a> |
<a href="#" onclick="play('QFCSXr6qnv4'); return false" style="color:#9b9898; font-size:12">Charlie 2</a> |
<a href="#" onclick="play('eaCCkfjPm0o'); return false" style="color:#9b9898; font-size:12">Charlie 3</a>
This uses the SWFObject and JQuery libraries. SWFObject is what handles loading the flash movie. JQuery is not strictly necessary here, I am just using it to load a default video when the page has loaded completely $(document).ready
. I point to the google hosted libraries, but you can download them and serve them locally if you would prefer.
Upvotes: 2