在HTML5独立应用程序iOS 8.3中嵌入YouTube视频,以打开YouTube应用程序

在HTML5独立应用程序iOS 8.3中嵌入YouTube视频,以打开YouTube应用程序

问题描述:

苹果最近修复了iOS 8上的错误,YouTube视频无法在WebApp上播放(为什么HTML5视频不能在IOS 8 WebApp(webview)中播放?)。 iOS 8.3中修正了这个错误,但我遇到了另一个问题。当YouTube视频嵌入页面时,视频将在YouTube应用中打开(如果已安装在iPad上)

Apple recently fixed the error on iOS 8 where YouTube videos would not play on a WebApp (Why HTML5 video doesn't play in IOS 8 WebApp(webview)?). This error was fixed in iOS 8.3 but I've come across another problem. When a YouTube video is embedded on the page, the video will be opened in the YouTube app if it is installed on the iPad

<!DOCTYPE html>
<head>
<meta charset="utf-8">
<meta name="apple-mobile-web-app-capable" content="yes" />
<title>HTML5 Video Standalone Test</title>
<style>
    body {
        margin:0;
    }
</style>
</head>
<body>
    <iframe width="700" height="394" src="//www.youtube.com/embed/xspoREpBOhY?rel=0" frameborder="0" allowfullscreen></iframe>
</body>
</html>

如果我在Safari中正常打开页面,那么它可以正常工作。视频不会自动播放,并在用户触摸它时在浏览器中播放。如果我删除了YouTube应用,那么WebApp也会按预期工作。

If I open the page in Safari normally then it works correctly. The video does not autoplay and it plays in the browser when the user touches it. If I delete the YouTube app then the WebApp works as expected as well.

如果安装了YouTube应用,则该用户将从WebApp中取出并放入YouTube应用。如果在打开的页面上存在视频,则会发生这种情况。视频不必自动播放选择,或者用户无法播放视频。它们会自动从WebApp中删除。

If the YouTube app is installed then the user is taken out of the WebApp and put into the YouTube app. This happens if a video exists on the page that is opened. The video doesn't have to autoplay selected or the user doesn't have the option to play the video. They are automatically taken out of the WebApp as the default.

有没有办法防止这种情况发生而无需从iPad上删除YouTube应用程序?

Is there a way to prevent this from happening without having to delete the YouTube app off of the iPad?

我被发送 Apple支持社区的这个答案。我所要做的就是在iframe的src中添加'-nocookie'。

I was sent this answer from the Apple Support Communities. All I had to do was to add '-nocookie' after youtube in the src of the iframe

<!DOCTYPE html>
<head>
<meta charset="utf-8">
<meta name="apple-mobile-web-app-capable" content="yes" />
<title>HTML5 Video Standalone Test</title>
<style>
   body {
    margin:0;
   }
</style>
</head>
<body>
    <iframe width="700" height="394" src="//www.youtube-nocookie.com/embed/xspoREpBOhY?rel=0" frameborder="0" allowfullscreen></iframe>
</body>
</html>

在我的测试应用中,它对我有用。

It worked for me in my test app.