是否可以在页面加载时启动fancybox iframe? [英] Is it possible to launch a fancybox iframe on page load?

查看:139
本文介绍了是否可以在页面加载时启动fancybox iframe?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经用Google搜索" fancybox,请在整个下午打开onload ",但似乎所有答案都与我要执行的操作不符.我的fancybox设置如下所示: www.casedasole.it/fancybox/ 即启动iframe.

I have googled "fancybox, open onload" all afternoon, but none of the answers seems to match what I'm trying to do. My fancybox set-up works like this: www.casedasole.it/fancybox/ i.e. it launches an iframe.

fancybox网站 给出了两个Launch fancyBox on page load的示例(第10点) ,但在两种情况下都在处理图像.

The fancybox website gives two examples of Launch fancyBox on page load (point 10), but in both cases it's handling images.

我要显示的框是带有文本的 iframe ,其中的链接在iframe中打开. 我找到了一种在fancybox窗口中打开加载隐藏div的方法(请参见 JSFiddle ).我知道,它可以正常工作- www.casedasole.it/fancybox/ok.html -实际上,它结合了两种启动iframe内容的方式-作为启动页面中的弹出式隐藏div,也可以通过该页面的启动按钮来启动iframe(关闭div生成的窗口)查看).

The box I want to appear is an iframe with text, and links in it open within the iframe. I found a way of opening onload a hidden div as a fancybox window (see JSFiddle). I got that to work - www.casedasole.it/fancybox/ok.html - in fact it combines both ways of launching the iframe content - as a pop-up hidden div in the launch page, and also from that page's launch button, which launches the actual iframe (close the div-generated window to see).

但是,打开onload的不是iframe,因此其中的任何链接都会打开一个新页面.

BUT, what opens onload is not an iframe - so any links within it will open a new page.

因此,有人知道是否有可能在加载时启动 iframe 幻想盒吗?我感觉不是.

So, anybody know if it's possible to launch a fancybox iframe onload? I get the feeling it's not.

推荐答案

很简单.您只需要使用type API选项(如

It's simple. You just need to specify the type of content you want to open using the type API option like

jQuery(document).ready(function ($) {
    $(".fancybox").fancybox({
        type: "iframe" // <-- whatever content : image, inline, swf, etc.
    }).trigger("click");
}); // ready

通知,我们链接了.fancybox().trigger()方法.

Notice we chained the .fancybox() and .trigger() methods.

上面的代码假定您在页面的某处具有此html:

The code above assumes you have this html somewhere in your page :

<a class="fancybox" href="http://example.com">this link open external page on an iframe</a>

请参见 JSFIDDLE

See JSFIDDLE

如果不想像上面的示例那样链接到页面,另一种选择是像这样通过编程方式触发fancybox:

Another option, if you don't want to have a link to the page as in the example above, is to trigger fancybox programmatically like :

jQuery(document).ready(function ($) {
    $.fancybox({
        href: "http://example.com",
        type: "iframe" // <-- whatever content image, inline, swf, etc
    });
}); // ready

注意,在这种情况下,您需要使用href API选项传递要打开的页面的URL.

Notice that in this case, you need to pass the URL of the page you want to open using the href API option.

查看更新的 JSFIDDLE

See updated JSFIDDLE

这篇关于是否可以在页面加载时启动fancybox iframe?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆