Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

jquery - AJAX and YouTube: 'X-Frame-Options' to 'SAMEORIGIN'.

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.

Ran into trouble trying to get YouTube videos to work, it's setup like this.

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.

Refused to display 'http://www.youtube.com/watch?v=myvideo' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.

Also tried adding <iframe> into <li> with display: none; with same result.

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The error means that the document may only be used as iframe inside documents located at www.youtube.com

Use the URL of the embed-code instead:

http://www.youtube.com/embed/myvideo

it will send a X-Frame-Options-header with a value of ALLOWALL


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...