开发者

Lightbox not loading

开发者 https://www.devze.com 2023-01-03 23:31 出处:网络
// Lightbox $(\'a.lightbox\').click(function () { $.getScript(\"js/lightbox.js\", function () { alert(\'Load Complete\');
// Lightbox
    $('a.lightbox').click(function () {
        $.getScript("js/lightbox.js", function () {
            alert('Load Complete');
            $("a.lightbox").lightbox({
                'type': 'iframe',
                'overlayOpacity': 0.6,
                'width': 940,
      开发者_JAVA百科          'hideOnContentClick': false
            });
        });
    });

I want to load script on first request, but it doesn't seem to work, the page just redirects to the linked website, does not open iframe in lightbox.

Thanks for your help.


You need to return false to prevent the event from propagating:

What is actually happening is that when the link is clicked, the code executes, but the event is finished, at which point the href attribute of the link (if it exists) is then redirected to.

(function($) {
    $(function() {
        $.getScript("js/lightbox.js", function () {
            alert('Load Complete');
            $('a.lightbox').click(function () {

               $("a.lightbox").lightbox({
                  'type': 'iframe',
                  'overlayOpacity': 0.6,
                  'width': 940,
                  'hideOnContentClick': false
               });
               return false;
            });  
        });
        $('a.lightbox').click();
   });
})(jQuery);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号