【发布时间】:2018-04-12 13:51:53
【问题描述】:
如果您访问《守望先锋》官方网站 (https://playoverwatch.com/en-us/) 并单击“观看预告片”按钮,则 youtube 视频将出现在同一网站上,而无需将您定向到该视频所在的原始 youtube 页面从。他们是怎么做到的?
【问题讨论】:
-
Youtube 为您在页面 HTML 中插入的每个视频提供了一个嵌入标签。
如果您访问《守望先锋》官方网站 (https://playoverwatch.com/en-us/) 并单击“观看预告片”按钮,则 youtube 视频将出现在同一网站上,而无需将您定向到该视频所在的原始 youtube 页面从。他们是怎么做到的?
【问题讨论】:
它被称为使用嵌入视频。你可以使用iframes
YouTube 视频 ID
当您打开视频时,YouTube 会显示一个 ID(如 vhjTYfG)。您可以使用此 ID,并在 HTML 代码中引用您的视频。
要在网页上播放您的视频,请执行以下操作:
- Upload the video to YouTube
- Take a note of the video id
- Define an <iframe> element in your web page
- Let the src attribute point to the video URL
- Use the width and height attributes to specify the dimension of the player
- Add any other parameters to the URL (see below)
这是一个示例代码,
<iframe width="420" height="315"
src="https://www.youtube.com/embed/vhjTYfG">
</iframe>
*在此处阅读更多信息。 w3schools
【讨论】:
Vishwa 先生是对的。我只是想补充。
请看一下这个网址 https://developers.google.com/youtube/iframe_api_reference
playoverwatch.com 正在使用类似的技术
【讨论】: