jquery - 将 Youtube 嵌入 Modal 时出现访问被拒绝错误

标签 jquery iframe youtube modal-dialog

我有一个页面,用户可以在其中将 Youtube 视频发布到论坛。

用户发布视频链接后,链接将转换为如下内容:

<a href='javascript:void(0)' class='video_player' data-videoid='http://www.youtube.com/embed/$vidID'>$video_title</a>

$vidID 只是您在每个 YouTube 视频的 URL 中看到的 YouTube 视频 ID。当用户单击链接播放视频时,会打开一个包含嵌入视频的模式。这是模态的 JS:

$('.video_player').live('mouseover', function(event) {//VIDEO PLAYER MODAL
    var videoid = $(this).attr("data-videoid");
    var sourcepage = $(this).attr("data-sourcepage");
    $(this).qtip({
     id: 'videomodal',
     content: {
            text: '<img src="images/loading.gif" alt="Loading..." /> Loading..please wait.',
            ajax: {url: 'modals/video_player.php',type: 'GET',data: { videoid: videoid, sourcepage: sourcepage}},
            title: { text: 'Video Player', button: true }
     },
     position: {    my: 'center', at: 'center', target: $(window) },
     show: { event: 'click', solo: true, modal: true },
     hide: false,
     style: 'ui-tooltip-tipsy ui-tooltip-rounded higher-zindex',
     events: {
        hide: function(event, api){
         auto_refresh = setInterval(function (){$('#bottom_middle').load(thisurl + '&timer=' + new Date().getTime() + ' #bottom_middle' );}, 5000);             
         $(this).qtip("destroy"); 
        }
     },  
    });
return false;
});

这是我的 video_Player.php 代码:(非常基本,模式加载此页面,并嵌入播放视频所需的 iframe)

<?PHP
 $videoid = $_GET['videoid'];
 $sourcepage = $_GET['sourcepage'];

 echo "<iframe title='YouTube video player' width='480' height='390' src='$videoid' frameborder='0' allowfullscreen></iframe>";   
?>

在 Chrome 中,我收到“不安全的 JavaScript 尝试使用 URL blah blah 访问帧”错误,但视频播放并且一切似乎都正常工作,但在 IE 中,我收到 SCRIPT5:访问被拒绝。我已经在网络和这个网站上搜索了解决方案,但运气不佳。有人知道解决此问题的方法或更好的方法吗?我使用了模态(qtip2),这是唯一的要求。我的所有 jquery 库也都是最新的。

最佳答案

尝试将其添加到您的代码中:

$('iframe').each(function(){
    var url = $(this).attr("src");
    $(this).attr("src",url+"?wmode=transparent");
});

关于jquery - 将 Youtube 嵌入 Modal 时出现访问被拒绝错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10166067/

相关文章:

android - 单击按钮后如何在YouTube上播放视频?

YouTube Api v3 - 主题 channel 视频

javascript - 在网站的新页面上保持事件菜单打开

javascript - Selenium IE Webdriver 悬停在元素上闪烁

c# - 文本框中文本的消失和重新出现

javascript - 在 Windows 8 Metro 应用程序中使用 iframe

javascript - 如何禁用点击但仍允许在 iframe 中滚动?

javascript - 错误: Failed to execute 'dispatchEvent' on 'EventTarget'

javascript - 从youtube播放列表ID中检索视频ID的数组

javascript - 调用变量 jQuery 函数