我有一个嵌入式管视频
<iframe width="490" height="279" src="http://www.youtube.com/embed/X7ab_dVhkWk?version=3&enablejsapi=1" frameborder="0" allowfullscreen></iframe>
嵌入时的html
<embed width="100%" height="100%" id="video-player-flash" type="application/x-shockwave-flash" src="http://s.ytimg.com/yt/swfbin/watch_as3-vflCBBX6J.swf" allowscriptaccess="always" allowfullscreen="true" bgcolor="#000000" flashvars="el=embedded&fexp=904544%2C909703%2C920701&is_html5_mobile_device=false&allow_ratings=1&allow_embed=1&tabsb=1&sendtmp=1&hl=en_US&eurl=http%3A%2F%2Fdev.springcorp.co.uk%2Fhistoricscotland%2Fstirling%2Ffacebook-april2012%2F&iurl=http%3A%2F%2Fi2.ytimg.com%2Fvi%2Fai55pL37saU%2Fhqdefault.jpg&view_count=117&title=Regent%20Arran%20Stirling%20Castle%20TV%20ad%202012&avg_rating=0&video_id=ai55pL37saU&length_seconds=31&iurlmaxres=http%3A%2F%2Fi2.ytimg.com%2Fvi%2Fai55pL37saU%2Fmaxresdefault.jpg&enablejsapi=1&sk=UX8fbMJpKT-VH3IVkWhtN7gCKU1r3TSzC&rel=1&playlist_module=http%3A%2F%2Fs.ytimg.com%2Fyt%2Fswfbin%2Fplaylist_module-vflfGS7wE.swf&iurlsd=http%3A%2F%2Fi2.ytimg.com%2Fvi%2Fai55pL37saU%2Fsddefault.jpg&jsapicallback=ytPlayerOnYouTubePlayerReady&playerapiid=player1&framer=http%3A%2F%2Fdev.springcorp.co.uk%2Fhistoricscotland%2Fstirling%2Ffacebook-april2012%2F">
如何使用Javacript停止此视频?
答案 0 :(得分:1)
最后我不得不使用api嵌入,所以我参考了视频。 (xxxx是视频的youtube ID)
<div id="player"></div>
<div id="player2"></div>
<div id="player3"></div>
<script>
//Load player api asynchronously.
var tag = document.createElement('script');
tag.src = "http://www.youtube.com/player_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var done = false;
var player;
var player2;
var player3;
function onYouTubePlayerAPIReady() {
player = new YT.Player('player', {
height: '279',
width: '490',
videoId: 'xxxxxxxx',
});
player2 = new YT.Player('player2', {
height: '279',
width: '490',
videoId: 'xxxxxxx',
});
player3 = new YT.Player('player3', {
height: '279',
width: '490',
videoId: 'xxxxxx',
});
}
function stopVideo() {
player.stopVideo();
}