Using fancybox on a loaded AJAX page

I searched in this group and searched on google, but still no luck in the answers. I also see that some of them have my problem, but the threads did not help, so I'm here

The question is simple, and to help you, I have packaged .zip using files that you can check

http://www.ivanhalen.com/fancyproblem.zip

  • I have a main page with some links (index.php)
  • Clicking on them loads an AJAX code snippet (page.php)
  • The fragment has one or more links, clicking on them should open iframed fancybox (fb.php)

Well, fancybox just won’t work, except for the first open link. Then I keep getting the error "t is not defined" in Firefox, which indicates me nowhere I tried everything I could imagine, but still no luck ...

Please can you help me? Many thanks

+3
source share
1 answer

Do not put the script in fancybox()your links in the content of the ajax response. Instead, you should move the call fancybox()to the callback of complete()the load function, for example:

$(document).ready(function(){
    $('#links a').live('click', function(e){
        e.preventDefault();
        var url = $(this).attr('href');
        $('#content').load(url, function(data, stat, req){
            $("a#popup").fancybox();
        });
    })
});
+4
source

Source: https://habr.com/ru/post/1772688/


All Articles