jQuery fancybox - 在iframe中定位特定div #id

Mr *_*ood 6 jquery fancybox

是否可以使用fancybox从另一个页面加载特定的div #id而不是通过iframe加载整个页面?

例如,我可以使用

 $('#link-whole').fancybox({
                'width'             : '80%',
                'height'            : '80%',
                'type'              : 'iframe',
            });
Run Code Online (Sandbox Code Playgroud)

<a id="link-whole" href="somepage.html">link 1</a>
Run Code Online (Sandbox Code Playgroud)

将所有'somepage.html'加载到iframe中,但是如何加载来自id为"target"的div的内容(例如)?

Pet*_*dIt 15

如果页面与您打开fancybox的页面位于同一个域上,则应该能够使用jQuery.ajax的dataFilter选项将返回的数据过滤到所需的目标ID.

$('#link-whole').fancybox({
    'width': '80%',
    'height': '80%',
    'type': 'ajax',
    'ajax': {
        dataFilter: function(data) {
            return $(data).find('#yourTargetID')[0];
        }
    }
});
Run Code Online (Sandbox Code Playgroud)