我知道youtube现在使用<iframe>
标记来嵌入<object>
的嵌入式视频。我有一些遗留代码,需要使用<object>
代码实现的全屏模式。是否有可能以某种方式强制使用<object>
标记的原生全屏模式?
<object
width="560"
height="350"
data="http://www.youtube.com/v/B8IIyYpqb5w&fs=1"
type="application/x-shockwave-flash">
<param name="wmode" value="opaque" />
<param name="allowFullScreen" value="true" />
<param name="src" value="http://www.youtube.com/v/B8IIyYpqb5w&fs=1" />
</object>
我还在网址中尝试了&fs=1
和&fullscreen=1
参数,但没有运气。
答案 0 :(得分:0)
不幸的是,您必须使用<iframe>
。由于 <object>
而 <embed>
根据w3schools从2015年1月开始弃用,因此您遇到此限制。
基于此片段:
<body>
<div>
<object
type="application/x-shockwave-flash"
data="http://www.youtube.com/v/Wd1Iz6j4WC0"
width="425"
height="355">
<param name="movie" value="http://www.youtube.com/v/Wd1Iz6j4WC0">
<param name="allowFullScreen" value="true"></param>
</object>
</div>
<iframe src="//www.youtube.com/embed/Wd1Iz6j4WC0" width="640" height="360" frameborder="0" allowfullscreen="allowfullscreen"></iframe>
</body>
对象标记继续体验“全屏不可用”,而iframe按预期运行。
或者你可以使用它:
<!DOCTYPE html>
<html>
<body>
<!-- 1. The <iframe> (and video player) will replace this <div> tag. -->
<div id="player"></div>
<script>
// 2. This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// 3. This function creates an <iframe> (and YouTube player)
// after the API code downloads.
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '390',
width: '640',
videoId: 'M7lc1UVf-VE',
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
// 4. The API will call this function when the video player is ready.
function onPlayerReady(event) {
event.target.playVideo();
}
// 5. The API calls this function when the player's state changes.
// The function indicates that when playing a video (state=1),
// the player should play for six seconds and then stop.
var done = false;
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.PLAYING && !done) {
setTimeout(stopVideo, 6000);
done = true;
}
}
function stopVideo() {
player.stopVideo();
}
</script>
</body>
</html>
下面的示例HTML页面创建了一个嵌入式播放器,可以加载视频,播放6秒钟,然后停止播放。
希望得到这个帮助。