No 'Access-Control-Allow-Origin' error while embeding youtube video

隐身守侯 提交于 2021-02-07 09:51:49

问题


here is my embed code:

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

here is the error in console

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.

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

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

how to solve this?


回答1:


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 Policy Reference




回答2:


add this to your .htaccess: Header set Access-Control-Allow-Origin "*"



来源:https://stackoverflow.com/questions/64973469/no-access-control-allow-origin-error-while-embeding-youtube-video

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!