LightBox problem while loading ? 7


If you have the following message error in ErrorShell (among others ;) )

element.dispatchEvent is not a function

while you are using (or trying) LightBox or one of his clones with Scriptaculous libraries, one solution of your problem could be to check that your Lightbox javascript file is not call before some Jquery’s…

Let’s take a totally random example from my website:

<script src="/js/prototype.js" type="text/javascript"> </script>
<script src="/js/scriptaculous.js?load=effects" type="text/javascript"> </script>
<script src="/js/lightbox.js" type="text/javascript"></script>

<script type="text/javascript" src="/js/jquery.js"></script>
<script type="text/javascript" src="/js/jquery.cookie.js"></script>

Doesn’t work because… Jquery’s files are cancelling the window.onload function !

So two ideas:
– Move or Lightbox’s links after the Jquery’s ones. Like that:
<script type="text/javascript" src="/js/jquery.js"></script>
<script type="text/javascript" src="/js/jquery.cookie.js"></script>


<script src="/js/prototype.js" type="text/javascript"> </script>
<script src="/js/scriptaculous.js?load=effects" type="text/javascript"> </script>
<script src="/js/lightbox.js" type="text/javascript"></script>

– Rewrite the Event observer from lightbox.js in after Jquery’s links. Like that:
<script type="text/javascript" src="/js/jquery.js"></script>
<script type="text/javascript" src="/js/jquery.cookie.js"></script>
Event.observe(window,'load',function(){ Lightbox.initialize(); });

Hope it helps. Have fun with Lightbox !

Fab
Latest posts by Fab (see all)

About Fab

Solutions Architect, I build great workflows for the news and media production industries. I play with data too.

Leave a comment

Your email address will not be published. Required fields are marked *

7 thoughts on “LightBox problem while loading ?

  • Myung Glaze

    Hi mate, your blog’s design is easy and clean and i like it. Your blog posts are fantastic. Please hold them coming. Greets!!!!

  • mitali

    i had try this but as footer containing the jquery if i write Event.observe(window,’load’,function(){ Lightbox.initialize(); });
    after including the footer file it will throws 2 errors:

    element.attachEvent is not a function in prototype.js (line 3917)
    element.dispatchEvent is not a function in prototype.js (line 3972)
    can any one help me?

    Thanks in Advance.

  • Fabien Post author

    @mitali it seems that your Lightbox is requiring prototype.js (and the lib is missing, you should include it before) instead of jQuery…