Is it possible to launch a fancybox iframe on page load?

感情迁移 提交于 2020-01-06 13:53:40

问题


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.

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

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).

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

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


回答1:


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

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

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>

See JSFIDDLE


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

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

See updated JSFIDDLE



来源:https://stackoverflow.com/questions/26366516/is-it-possible-to-launch-a-fancybox-iframe-on-page-load

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!