javascript - jQuery iframe 无法设置 youtube url

标签 javascript php jquery iframe youtube

我正在努力

这是我的 HTML 中的代码

<iframe class="embed-responsive-item"  id="placeYoutubeVideo"
        style="display:none" src="#" style="display:none" allowfullscreen></iframe>

在 jQuery 中,我试图更改视频的 src

var neww = 'https://youtu.be/NOubzHCUt48';
        $('#placeYoutubeVideo').prop('src', neww)

但它抛出以下错误:

Refused to display 'https://www.youtube.com/watch?v=NOubzHCUt48&feature=youtu.be' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.

我该如何解决这个问题?

如果不可能,是否可以通过点击功能生成带有 youtube url 的 iframe?

请帮忙。

最佳答案

试试这个

<iframe class="embed-responsive-item" id="placeYoutubeVideo" src="#" allowfullscreen></iframe> 
<script> 
$(document).ready(function () { 
var neww = 'http://www.youtube.com/embed/NOubzHCUt48'; $('#placeYoutubeVideo').attr('src', neww); }); 
</script>

https://jsfiddle.net/vyt7gxwz/

HTTP -> HTTPS = ERROR (X-Frame-Options' to 'SAMEORIGIN)

HTTP -> HTTP = OK

HTTPS -> HTTPS = OK

HTTPS -> HTTP = ERROR (X-Frame-Options' to 'SAMEORIGIN)

关于javascript - jQuery iframe 无法设置 youtube url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34493017/

相关文章:

javascript - 在 window.onbeforeunload 中等待消息发送?

javascript - 在 JavaScript 中渲染 B 样条动画的问题

php - 当 "--width"=> 1140 时使用 wkhtmltoimage 的超大图像

php - 链接到页面上的 id 但重新定位

javascript - 将 TD 值作为其文本

javascript - 提交隐藏后HTML5输入表单重现

php - sql查询速度慢

javascript - 如何防止点击搜索时出现默认jquery

javascript - HTML/Javascript 在文件上传前访问 EXIF 数据

javascript - 更改 CSS :before if and ID has a specific class