简体   繁体   English

网页加载时的jQuery Fancybox,iFrame中的内容

[英]jQuery Fancybox on page load, content in iFrame

I would like to load a fancybox when the document is ready, but in a specific DIV and the content of the fancybox will be from a different page, displayed as an iFrame. 我想在准备好文档时加载一个fancybox,但在特定的DIV中,fancybox的内容将来自另一个页面,显示为iFrame。 This is what I currently have: 这是我目前拥有的:

$(document).ready(function () {     
     $.fancybox({
          'href'            : "#div",
          'content'         : "content.jsp",
          'type'            : "iframe",
     });
});

HTML: HTML:

<div id="div">
</div>

Nothing is loading in. 什么都没有加载。

Try this: 尝试这个:

$(document).ready(function () {     
     $("#div").fancybox({
          'href'            : 'content.jsp',
          'type'            : 'iframe'
     });
});

HTML HTML

<div id="div">
    Click Here
</div>

JsFiddle 的jsfiddle

You cannot display the contents of a div as iframe but inline . 您不能将div的内容显示为iframe而是inline

So you either open (programmatically) the content.jsp file directly in fancybox as iframe like : 因此,您可以像使用iframe一样直接在fancybox中(以编程方式)打开content.jsp文件:

jQuery(document).ready(function ($) {
    $.fancybox({
        href: "content.jsp",
        type: "iframe"
    });
}); // ready

Or load the contents of the content.jsp file into the div#div container and then show that inline content in fancybox like : 或将content.jsp文件的内容加载到div#div容器中,然后在fancybox中显示内联内容,例如:

jQuery(document).ready(function ($) {
    $("#div").load("content.jsp", function () {        
            $.fancybox($(this), {
                // API options
                type: "inline"
            });
    });
}); // ready

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM