youtube 嵌入视频错误 NO ACCESS-CONTROL-ALLOW-ORIGIN [英] youtube embeded video error NO ACCESS-CONTROL-ALLOW-ORIGIN

查看:31
本文介绍了youtube 嵌入视频错误 NO ACCESS-CONTROL-ALLOW-ORIGIN的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如您在此处看到的

解决方案

您忘记将 &origin=https://yourdomain.com 添加到您的 iframe src,此值允许 YouTube 添加其响应的正确标头.

As you can see here https://mohamed-hassan.com/samples/project24/ , if you open the console you will see this error

(ZYLR4KocS2Q?enablejsapi=1&autoplay=1&mute=1&controls=0&showinfo=0&modestbranding=1&rel=0:1 Failed to load https://googleads.g.doubleclick.net/pagead/id: Redirect from 'https://googleads.g.doubleclick.net/pagead/id' to 'data:text;charset=utf-8,' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://www.youtube.com' is therefore not allowed access.)

I just embedded video from youtube using iframe tag and I added at the top of the index file header('Access-Control-Allow-Origin: *'); but still get this error.

Here is a screenshot

解决方案

You forgot to add &origin=https://yourdomain.com to your iframe src, this value allows YouTube to add the proper headers to its response.

这篇关于youtube 嵌入视频错误 NO ACCESS-CONTROL-ALLOW-ORIGIN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆