javascript 在移动浏览器上单击按钮以全屏播放 youtube 视频
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16763496/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Play youtube video in fullscreen on button click on mobile browsers
提问by garethdn
I want to play a youtube video in fullscreen on click of a button. I currently have the following iframe
:
我想通过单击按钮全屏播放 YouTube 视频。我目前有以下几点iframe
:
<div class="youtube-trailer">
<iframe class="youtube-player" type="text/html" src="http://www.youtube.com/embed/whatever" allowfullscreen frameborder="0"></iframe>
</div>
On Safari Mobile, specifically, when a press the Play button the video launches in full screen which is the desired behavior. This is fine. I don't want the iframe
displayed on the page though. I just want a button that will open the video in fullscreen using the native video player. i.e. i don't want to create an overly-elaborate lightbox to house the video.
具体而言,在 Safari Mobile 上,当按下“播放”按钮时,视频将以全屏模式启动,这是所需的行为。这可以。我不希望iframe
显示在页面上。我只想要一个按钮,可以使用本机视频播放器全屏打开视频。即我不想创建一个过于复杂的灯箱来放置视频。
Anyone have any ideas?
有人有想法么?
回答by Victor Paredes
The standard youtube video link format is:
标准的 youtube 视频链接格式是:
http://www.youtube.com/watch?v=Lv-sY_z8MNs
You can link directly to the full screen video (without opening a new window) by adding "_popup" after "watch" in the URL:
您可以通过在 URL 中的“观看”之后添加“_popup”来直接链接到全屏视频(无需打开新窗口):
http://www.youtube.com/watch_popup?v=Lv-sY_z8MNs
This should work for both mobile and desktop browsers. Naturally, if you did end up wanting to open your link in a new page, simply add "target="_blank" to your opening anchor tag.
这应该适用于移动和桌面浏览器。当然,如果您最终想在新页面中打开您的链接,只需将“target="_blank”添加到您的起始锚标记中即可。