【问题标题】:HTML Button Opens Youtube VideoHTML 按钮打开 Youtube 视频
【发布时间】:2015-10-21 01:22:24
【问题描述】:

我是 HTML 新手,所以也许这很容易/简单回答。当用户单击我的 html 脚本上的按钮时,我正在尝试将 youtube 视频弹出到全屏。我熟悉 youtube player API 和 javascript,但我不确定如何通过 HTML 实现这一点(我已经用 iOS 完成了)。关于如何实现这一点的任何建议?谢谢!

【问题讨论】:

    标签: javascript html ytplayer


    【解决方案1】:

    你需要创建这样的代码

    <a href="#" id="fix-fullscreen">Full screen</a>
    

    并使用 javascript 创建&lt;script&gt;

    var fullscreen = document.getElementById('fix-fullscreen'),
        player = document.getElementById('player');
    
    fullscreen.addEventListener('click', function (e) {
        if (~player.src.indexOf('?')) player.src += '&autoplay=1';
        else player.src += '?autoplay=1';
    
        var req = player.requestFullscreen
            || player.webkitRequestFullscreen
            || player.mozRequestFullScreen
            || player.msRequestFullscreen;
    
        req.call(player);
        e.preventDefault();
    });
    

    希望对您有所帮助。

    【讨论】:

    • 我在哪里添加第一行代码?我如何通过单击按钮来调用它?到目前为止,我有&lt;div id="buttonSection"&gt; &lt;button type="button" onclick="popup()" style="width:310px";"height=75px"&gt;Play Video &lt;/button&gt;...只是不知道您的 sn-p 在哪里发挥作用...谢谢!
    • 添加类似&lt;button id="fix-fullscreen"的内容,然后在&lt;script&gt;here&lt;/script&gt;标签内插入javascript代码
    • 对不起,如果你需要全屏,你不需要设置弹出窗口。
    • onClick 调用什么函数?你给我的js代码应该也有ytplayer api吗?谢谢
    • onclick 事件发生在用户点击一个元素时,在这个例子中是当你点击button 时。 js 代码不需要 youtube API。尝试将我提供的所有代码放入嵌入 youtube 视频的 html 中。
    猜你喜欢
    • 2015-09-13
    • 1970-01-01
    • 1970-01-01
    • 2022-07-25
    • 2021-04-07
    • 2011-12-08
    • 1970-01-01
    • 2011-02-02
    • 2013-02-08
    相关资源
    最近更新 更多