iframe 元素在 windows 浏览器上显示视频正常,但在 IOS 上不显示

iframe element displays video fine on windows browsers, but doesnt appear for IOS

问这个是为了分享我的解决方案,因为我搜索的时间太长,找不到这个解决方法,而且不是一个简单的答案...

所以:我的网站上嵌入了一个 YouTube 视频。它在我的 windows machine 上运行良好(Google Chrome、Edge、Firefox,所有测试和工作)。然而,当我在 iPhone chrome 浏览器上对其进行测试时,它什么也不显示,并使整个页面 link 返回主页。提供的 iframe 是:

<iframe width="560" height="315" src="https://www.youtube.com/embed/video_id" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

而且,就像我说的,在 Windows machines 上显示良好。我有一位同事在他的 mac 上使用网络检查器来查看代码是否未加载或类似的东西,但没有骰子。代码在两种浏览器中显示完全相同,并且没有错误(甚至没有跨站点错误)。

经过反复试验,我从 EncodeDNA (https://www.encodedna.com/html5/embed-youtube-video-in-a-webpage-without-iframe.htm) 得到了这个(极其简单的)解决方案。只需使用对象而不是 iframe:

<!DOCTYPE html>
<html>
<head>
    <title>Embed YouTube Video without iFrame</title>
</head>
<body>
    <object data='https://www.youtube.com/embed/video_id?autoplay=1' 
        width='560px' height='315px'>
    </object>
</body>
</html>

我将其插入并在所有浏览器上运行,包括(在本例中最重要的是)IOS 浏览器。