youtube embeded video error NO ACCESS-CONTROL-ALLOW-ORIGIN

杀马特。学长 韩版系。学妹 提交于 2021-02-10 17:53:29

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/51480196/youtube-embeded-video-error-no-access-control-allow-origin

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