javascript Fancybox:无法加载请求的内容。请稍后再试

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13495299/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 18:58:10  来源:igfitidea点击:

Fancybox: The requested content cannot be loaded. Please try again later

javascriptjqueryfancybox

提问by Sherlock

This particular topic has some answers on SO, but none of them solves my problem. I have no idea where to look here, although I suspect it's something very simple.

这个特定的主题在 SO 上有一些答案,但没有一个能解决我的问题。我不知道在哪里看,虽然我怀疑这很简单。

  • When I try to open a url in a Fancybox manually(i.e. by 'physically' clicking a link) it works.
  • If I however try to open it on page load automatically(i.e. by faking clicking a link), it doesn't work at all and gives me the error I mention in my title.
  • 当我尝试手动打开 Fancybox 中的 url (即通过“物理”单击链接)时,它可以工作。
  • 但是,如果我尝试在页面加载时自动打开它(即通过伪造单击链接),它根本不起作用,并且会出现我在标题中提到的错误。

The HTML is simple:

HTML 很简单:

<a href="http://www.mydomain.nl/url/to/whatever" class="fancybox hidden_link">test</a>

The Javascript I'm using to automatically click it, is pretty straightforward too:

我用来自动单击它的 Javascript 也非常简单:

$(document).ready(function() {              
    $(".hidden_link").fancybox().trigger("click");
});

The event goes off (a Fancybox opens), but it shows nothing more than the 'content cannot be loaded' message. I see my own page in the Fancybox when I click the link manually.

事件关闭(打开一个 Fancybox),但它只显示“内容无法加载”消息。当我手动单击链接时,我会在 Fancybox 中看到我自己的页面。

What am I missing here?

我在这里错过了什么?

回答by JFK

Having this link :

有这个链接:

<a href="http://www.mydomain.nl/url/to/whatever" class="fancybox hidden_link">test</a>

... this script :

...这个脚本:

$(document).ready(function() {
    $(".fancybox").fancybox({
        type: "iframe",
        width : 380, // or whatever
        height: 280
    }).trigger("click");
});?

... should do the job for both, manually and programmatically.

... 应该以手动和编程方式完成这项工作。

See JSFIDDLE

JSFIDDLE

Noticethat I used type: "iframe"since the content is an external page. The same origin policyshould be considered in any case.

请注意,我使用了type: "iframe"因为内容是外部页面。该同源策略应该在任何情况下予以考虑。

回答by Ivan Krechetov

That's one of the facets of same-origin policy. The exact behavior differs from browser to browser. See http://code.google.com/p/browsersec/wiki/Part2#Navigation_and_content_inclusion_across_domains

这是同源策略的一个方面。确切的行为因浏览器而异。请参阅http://code.google.com/p/browsersec/wiki/Part2#Navigation_and_content_inclusion_across_domains

Here's the summary per browser version.

这是每个浏览器版本摘要

There's clearly a security concern here, because clicking links with JavaScript can cause actions on your behalf. That may be destructive on sites where GET requests cause state change, because a header (like a cookie) authenticating you will be sent with that GET request as well.

这里显然存在安全问题,因为单击带有 JavaScript 的链接可能会导致代表您的操作。这可能对 GET 请求导致状态更改的站点具有破坏性,因为验证您的标头(如 cookie)也将与该 GET 请求一起发送。

回答by Kokers

Because there is something like same origin policy.

因为有类似同源政策的东西。

You get from google response: X-Frame-Options SAMEORIGIN

您从 google 回复中得到:X-Frame-Options SAMEORIGIN

If you link to subpage within your domain it should work.

如果您链接到域内的子页面,它应该可以工作。

回答by Raul Valverde

Here's a solution I gave the author a while.

这是我给作者一段时间的解决方案。

$(document).ready(function() {
    $.fancybox({
        content: $("#popup"),
        closeClick  : false,
        openEffect  : 'none',
        closeEffect : 'none',
        helpers   : {
            overlay : {
                closeClick: false,
            }
        }
    });
});

Link: http://jsfiddle.net/YkH5G/1/

链接:http: //jsfiddle.net/YkH5G/1/

By author plugin: https://github.com/fancyapps/fancyBox/issues/410

作者插件:https: //github.com/fancyapps/fancyBox/issues/410