jQuery fancybox - target specific div #id in iframe

后端 未结 3 1833
野性不改
野性不改 2020-12-06 13:13

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

          


        
相关标签:
3条回答
  • 2020-12-06 13:38

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

        return $(data).filter('#yourTargetID')[0];
    
    0 讨论(0)
  • 2020-12-06 13:56

    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];
            }
        }
    });
    
    0 讨论(0)
  • 2020-12-06 13:56

    You could target the specific part of the page using beforeShow

                      function opendialog(mypage) {
                      var linktoopen=mypage ;
                        $.fancybox({                        
                        'autoScale': false,
                        'transitionIn': 'elastic',
                        'transitionOut': 'elastic',
                        'speedIn': 500,
                        'speedOut': 300,                    
                        'width'         :  800,
                        'height'        :   410,
                        'autoDimensions': false,
                        'centerOnScroll': true,
                        'scrolling'   : 'no',
                        'type' :  'iframe',
                        'href' : linktoopen,
                          beforeShow: function(){
                              $(".fancybox-iframe").css({
                              margin  : "-380px 0 0",
                             height:"790px"
                           });
                         }
                        });
                        }
    
    0 讨论(0)
提交回复
热议问题