代码之家  ›  专栏  ›  技术社区  ›  Yan Tavares

如何在HTML中正确嵌入YouTube视频[重复]

  •  -1
  • Yan Tavares  · 技术社区  · 1 年前

    我试图在我的网站上嵌入一个Youtube视频,使用 iframe 标签但是,当使用Chrome时,控制台上会出现许多警告,例如:

    Reading cookie in cross-site context will be blocked in future Chrome versions

    我也在网上读到使用 iframe 由于安全原因不鼓励使用。

    为了避免破坏更改和安全问题,我想知道除了添加一个 video 标签,因为据我所知,阻止外部cookie是不可能的。

    这是我的代码:

    <!DOCTYPE html>
    <html lang="en">
      <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
      </head>
      <body>
        <iframe
          width="560"
          height="315"
          src="https://www.youtube.com/embed/dQw4w9WgXcQ?si=huEs0X_fKX95LMeh"
          title="YouTube video player"
          frameborder="0"
          allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
          allowfullscreen
        ></iframe>
      </body>
    </html>
    
    

    这是完整的警告日志:

    Reading cookie in cross-site context will be blocked in future Chrome versions
    
    Cookies with the SameSite=None; Secure and not Partitioned attributes that operate in cross-site contexts are third-party cookies. In future Chrome versions, reading third-party cookies will be blocked. This behavior protects user data from cross-site tracking.
    
    1 回复  |  直到 1 年前
        1
  •  1
  •   Tangentially Perpendicular    1 年前
    • 转到YouTube网站上的视频
    • 点击 Share
    • 点击 Embed
    • 将提供的HTML复制并粘贴到您自己的页面中。

    参考 https://support.google.com/youtube/answer/171780?hl=en