嵌入youtube视频时没有“访问控制允许来源"错误 [英] No 'Access-Control-Allow-Origin' error while embeding youtube video

查看:46
本文介绍了嵌入youtube视频时没有“访问控制允许来源"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的嵌入代码:

<iframe src="https://www.youtube-nocookie.com/embed/x9pRNcoP1EU" frameborder="0" allowfullscreen></iframe>

这是控制台中的错误

Access to XMLHttpRequest at 'https://googleads.g.doubleclick.net/pagead/id' from origin 'https://www.youtube-nocookie.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

我试图在php页面顶部添加以下内容-没有成功

I tried to add the following at the top of php page - without success

header("Access-Control-Allow-Origin: *");  

如何解决这个问题?

推荐答案

正如@ david-vielhuber在评论中所说,这与您的域无关,但与" googleads.g.上的CORS政策"相关.doubleclick.net ".除了改变嵌入YouTube视频的方式之外,您无能为力.

As @david-vielhuber said in the comments, this isn't related to your domain but to the CORS policy on "googleads.g.doubleclick.net". There is nothing you can do beyond changing the way you embed YouTube videos.

CORS政策参考

这篇关于嵌入youtube视频时没有“访问控制允许来源"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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