【发布时间】:2012-08-19 12:18:17
【问题描述】:
我正在使用 php 来创建 youtube 拇指,并且需要在 iframe 中使用 fancybox 调用它来打开 youtube 视频。 fancybox 2 常见问题解答告诉:
可以从 iframe 调用脚本吗? 如果所有必要的文件都包含在父窗口中,那么您可以:
<a href="javascript:parent.$.fancybox.open({href : 'myurl'});">Open something</a>
所以我这样做了,我的幻想框实际上按预期从 iframe 到父窗口打开。 唯一的问题是,它不是视频而是告诉“无法加载请求的内容。 请稍后再试” - 原因可能是 http:address 有问题,我看不到脚本错误在哪里。
我用来在 Iframe 中创建链接的脚本:
...some php here...
echo('
<div class="tube"><a title="'.$title.'" href="javascript:parent.Mybox.fancybox.open ({href : \'http://www.youtube.com/v/'.$v.'? feature=player_embedded&version=2&autohide=1&hd=1&modestbranding=1&rel=0&border=0&autoplay=0&fs=1&fmt=22 \'});"><img style="border:2px solid #000;margin:5px;" alt="'.$title.'" src="http://i1.ytimg.com/vi/'.$v.'/default.jpg"/></a>');
...some more php here...
它产生的结果是这样的
<div class="tube"><a title="MyTitle" href="javascript:parent.Mybox.fancybox.open({href : 'http://www.youtube.com/v/J0_5JEJdB5g?feature=player_embedded&version=2&autohide=1&hd=1&modestbranding=1&rel=0&border=0&autoplay=0&fs=1&fmt=22 '});"><img style="border:2px solid #000;margin:5px;" alt="MyVideo" src="http://i1.ytimg.com/vi/J0_5JEJdB5g/default.jpg"/></a><p>09.11.2012<br/>MyVideo<br/>213times</p></div>
那么我做错了什么? 'myurl' 或我的 fancybox 设置有什么问题?
我的fancybox设置是:
<script type="text/javascript">
Mybox(document).ready(function() {
Mybox('#tubeframe')
.attr('rel', 'media-gallery')
.fancybox({
openEffect : 'elastic',
closeEffect : 'fade',
prevEffect : 'none',
nextEffect : 'none',
padding : 0,
autoScale : true,
fitToView : true,
height : 475,
width : 846,
fixed : true,
arrows : false,
helpers : {
media : {},
buttons : {},
title: {
type: 'outside'
},
overlay : {
opacity: 0.7,
css : {
'background-color' : '#433'
}
}
}
});
});
</script>
【问题讨论】:
-
在我的情况下,fancybox 实际上从子页面无缝打开,没有错误。它只是不打开视频文件!有趣的是这里stackoverflow.com/questions/8853727/call-fancybox-in-parent-from-iframe没有使用fancybox官方方法href="javascript:parent.$.fancybox.open({href : 'myurl'} );" - 这行得通吗?
标签: php jquery fancybox-2