Javascript Fancybox 返回“无法加载请求的内容。请稍后再试。”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4941002/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Fancybox returning " The requested content cannot be loaded. Please try again later."
提问by Brian
Using Fancyboxto play youtube videos in a modal box.
使用的fancybox到一个模式对话框播放YouTube视频。
My Problem is that I keep getting "The requested content cannot be loaded. Please try again later."
我的问题是我不断收到“无法加载请求的内容。请稍后再试。”
The modal box is popping up so I know the script is running, it might be a problem with my API call... here is my call:
模态框正在弹出,所以我知道脚本正在运行,这可能是我的 API 调用有问题……这是我的调用:
<script type="text/javascript">
$(document).ready(function() {
/* This is basic - uses default settings */
$("a.fancybox").fancybox({
'hideOnContentClick': true
});
/* This is a non-obtrustive method for youtube videos*/
$("a[rel=fancyvideo]").fancybox({
overlayShow: true,
frameWidth:640,
frameHeight:360,
});
});
</script>
采纳答案by mu is too short
Do you have any <a>
s with both class="fancybox"
and rel="fancyvideo"
? If you do then you'll be binding Fancybox to those elements twice and Fancybox might not like that. Try taking out this one:
你有<a>
sclass="fancybox"
和srel="fancyvideo"
吗?如果这样做,那么您将两次将 Fancybox 绑定到这些元素,而 Fancybox 可能不喜欢那样。尝试取出这个:
$("a.fancybox").fancybox({
'hideOnContentClick': true
});
And see what happens with just the second one in place.
看看第二个就位会发生什么。
UPDATE: Strange. The demo (http://chadly.net/demos/video-lightbox.html) is producing different HTML than your page, the demo builds an <object data=...>
but yours builds a <object><embed src="youtube-url">
thing. You're saying:
更新:奇怪。演示 (http://chadly.net/demos/video-lightbox.html) 生成的 HTML 与您的页面不同,演示构建了<object data=...>
一个<object><embed src="youtube-url">
东西,但您构建了一个东西。你是说:
type: 'swf'
in your Fancybox binding, that's where the <object><embed>...</embed></object>
stuff comes from. However, the href
points at a plain old YouTube video viewing HTML page and that href
ends up as the src
attribute for the <embed>
. The URL for embedding a YouTube video isn't the same as the video's HTML page and that's probably the source of your problem.
在您的 Fancybox 绑定中,这就是这些<object><embed>...</embed></object>
东西的来源。然而,href
在一个普通的旧的YouTube视频浏览HTML网页点和href
最终成为了src
该属性<embed>
。嵌入 YouTube 视频的 URL 与视频的 HTML 页面不同,这可能是问题的根源。
Try replacing the href
that looks like this:
尝试替换href
看起来像这样的:
http://www.youtube.com/watch?v=QmVvgSfdmJQ
with one like this:
像这样:
http://www.youtube.com/embed/QmVvgSfdmJQ
The first is the plain HTML page for YouTube, the second is the embeddable SWF.
第一个是 YouTube 的纯 HTML 页面,第二个是可嵌入的 SWF。
UPDATE 2: The example you're working from is for Fancybox 1.0.0 but you're using 1.3.4, 1.0.0 has some special checks for YouTube that aren't present in later versions:
更新 2:您正在使用的示例适用于 Fancybox 1.0.0,但您使用的是 1.3.4,1.0.0 对 YouTube 进行了一些特殊检查,这些检查在更高版本中不存在:
//...
} else if (url.match(/youtube\.com\/watch/i)) {
//...
That's from 1.0.0 and the code after that else if
rewrites the HTML page URL (e.g. http://www.youtube.com/watch?v=QmVvgSfdmJQ
) to the older embeddable SWF URL (e.g. http://www.youtube.com/v/QmVvgSfdmJQ
). This version problem also explains why the demo was producing different HTML than your's.
那是从 1.0.0 开始,之后的代码else if
将 HTML 页面 URL(例如http://www.youtube.com/watch?v=QmVvgSfdmJQ
)重写为旧的可嵌入 SWF URL(例如http://www.youtube.com/v/QmVvgSfdmJQ
)。这个版本问题也解释了为什么演示生成的 HTML 与您的不同。
So, you have some version problems on top of everything else.
因此,除了其他所有问题外,您还有一些版本问题。
回答by Kamika
Check if you have included the jquery.fancybox-media.js
检查您是否包含了jquery.fancybox-media.js
<script type="text/javascript" src="jquery.fancybox-media.js?v=1.0.0"></script>
回答by kovarov
use this sample don't forget href
使用此示例不要忘记 href
<a class="fancybox" href="your path for image or other">
<img src="imagepath">
</a>
回答by Nick
Looks like your code might be slightly off
看起来您的代码可能略有偏差
<script type="text/javascript">
$(document).ready(function() {
$("a[@rel*=fancyvideo]").fancybox({
overlayShow: true,
frameWidth:640,
frameHeight:360
});
});
</script>
http://chadly.net/post/2009/01/29/Lightbox-for-YouTube-Videos.aspx
http://chadly.net/post/2009/01/29/Lightbox-for-YouTube-Videos.aspx