Uncaught TypeError: Object [object Object] has no method “fancybox”

不打扰是莪最后的温柔 提交于 2019-12-18 14:47:33

问题


I have really strange problem with fancybox(2.x). I was using this script for ages but i hadn't experienced such problem before.

So, i have website: http://tinyurl.com/6mx7an8 and i've included every jquery/fancybox files as manual says but the JS console gives me the error

Uncaught TypeError: Object [object Object] has no method 'fancybox'

Have you any idea what am i doing wrong? Any help would be appreciated :)


回答1:


There are couple of issues in your website.

  1. You are including jQuery library 2 times one before and after including fancybox plugin js because of which the plugin which is added is cleared by second jQuery library inclusion.
  2. There is some other library which is overridding $, so your code is not working because $ is not an alias for jQuery anymore. You can use jQuery.noConflict() to avoid conflicts with other libraries on the page which use the same variable $.



回答2:


Looks like jQuery is included twice, once near the top of the head and once near the bottom.




回答3:


I had a similar problem. Somehow, jQuery was being loaded twice. Turns out while testing something, I added a drupal_add_js line to load jquery in a block, which was disabled, but Drupal still evaluated the PHP in the disabled block.

When I removed the drupal_add_js line from the block, jQuery loaded fine, once per page.




回答4:


I have a css unify php script on my website that added both jquery and jquery postmessage plugin into the same javascript file.

So it was giving me the error above.

I have loaded the jquery postmessage separately without unifying it and it stopped giving me the error.




回答5:


I got it working with this code

<script type="text/javascript">
    (function( $ ) {   
        $(document).ready( function( ) {  
            $("a#fancyBoxLink").fancybox({
                'href'   : '#popupvid',
                'titleShow'  : false,
                'transitionIn'  : 'elastic',
                'transitionOut' : 'elastic'
            });

        });
    })(jQuery);      
</script>



回答6:


Jquery sub library may included in main library ,For example jquery.ui.sortable.js i have included in jquery-ui.js while downloading and i added again it was giving a error for me.

script type="text/javascript" src="vendor/js/jquery-ui.js">

script type="text/javascript" src="vendor/js/jquery.ui.sortable.js">

so verify sub library included or not



来源:https://stackoverflow.com/questions/9070979/uncaught-typeerror-object-object-object-has-no-method-fancybox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!