Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery fancybox - target specific div #id in 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?

For example I can use

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

with

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

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

like image 570
Mr Jonny Wood Avatar asked Jun 16 '10 15:06

Mr Jonny Wood


2 Answers

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];
        }
    }
});
like image 81
PetersenDidIt Avatar answered Nov 13 '22 16:11

PetersenDidIt


If the find method doesn't work for you, try filter on the line inside dataFilter object.

    return $(data).filter('#yourTargetID')[0];
like image 30
Tom Roggero Avatar answered Nov 13 '22 17:11

Tom Roggero