AJAX 和 YouTube:“X-Frame-Options"到“SAMEORIGIN". [英] AJAX and YouTube: 'X-Frame-Options' to 'SAMEORIGIN'.
问题描述
我正在编写一个网站,通过 jQuery 动态加载内容.这样做的原因是让音频播放器保持运行状态,同时无需刷新即可浏览页面内容.
I'm writing a site where content is loaded dynamically via jQuery. The reason for this is to leave an audio player running while being able to navigate through page content without refresh.
在尝试让 YouTube 视频正常运行时遇到问题,设置如下.
Ran into trouble trying to get YouTube videos to work, it's setup like this.
站点内容使用 .load() 加载,对于视频页面,它包含指向 YouTube 视频的无序列表链接,每个链接都有一个空的 <div>
用于 <;iframe>
的.单击链接会增加 并将
嵌入视频.
Site content is loaded using .load(), and for the videos page it contains an unordered list of links to YouTube videos, and each with an empty <div>
for <iframe>
's. Clicking on a link grows the <li>
and embeds the <iframe>
with the video.
一切正常,除了 不会加载源代码,抛出这个错误.
Everything works well except the <iframe>
will not load the source, throwing this error.
拒绝显示http://www.youtube.com/watch?v=myvideo',因为它将 'X-Frame-Options' 设置为 'SAMEORIGIN'.
Refused to display 'http://www.youtube.com/watch?v=myvideo' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.
还尝试将 添加到
和
display: none;
中,结果相同.
Also tried adding <iframe>
into <li>
with display: none;
with same result.
我以为我了解 javascript 同域策略,但这超出了我的理解.谷歌搜索错误让我相信这是服务器端的东西?但这没有任何意义.
I thought I understood the javascript same domain policy, but this is beyond me. Googling the error leads me to believe it's something server side? But that doesn't make any sense.
很难摆弄这样的东西,希望它有意义.
Hard to fiddle something like this, hope it makes sense.
推荐答案
该错误意味着该文档只能用作位于 www.youtube.com 的文档内的 iframe
The error means that the document may only be used as iframe inside documents located at www.youtube.com
改用嵌入代码的 URL:
Use the URL of the embed-code instead:
http://www.youtube.com/embed/myvideo
它将发送一个 X-Frame-Options
-header,其值为 ALLOWALL
it will send a X-Frame-Options
-header with a value of ALLOWALL
这篇关于AJAX 和 YouTube:“X-Frame-Options"到“SAMEORIGIN".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!