jQuery Fancybox-在iframe中定位特定的div #id [英] jQuery fancybox - target specific div #id in iframe

查看:38
本文介绍了jQuery Fancybox-在iframe中定位特定的div #id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is it possible to use fancybox to load a specifc div #id from another page rather than loading the whole page via an iframe?

例如,我可以使用

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

使用

<a id="link-whole" href="somepage.html">link 1</a>

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

to load all of 'somepage.html' into the iframe but how would I load JUST the content from a div with the id "target" (for example)?

推荐答案

如果该页面与您在其中打开fancybox的页面位于同一域中,那么您应该可以使用 jQuery.ajax 可以将返回的数据过滤到所需的目标ID.

If the page is on the same domain of the page that you are opening the fancybox on then you should be able to use the dataFilter option of jQuery.ajax to filter the returned data down to the target ID that you want.

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

这篇关于jQuery Fancybox-在iframe中定位特定的div #id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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